我winform开发的东西
开始在datagridview里面数据数字没有关系.
后来点了下其他的什么text控件.再去输入数字,它永远都能输入一个字.就是好像按住的shift全部选中一样.
我把editmode全部改了.都不知道出在什么地方.大家有经验,可以告诉下不?急死个人.

解决方案 »

  1.   

    好好看看 各个控件里的paint事件里是不是有东西!
    或是你所说的text控件里有没有事件会影响到后面的输入!
    能想到的就这些了!
      

  2.   

    看看你的text控件的MaxLength的值的多少     不知道行不
      

  3.   

    点击的单元格里面有个事件.
    就是取得另一个单元格的值string price=this.datagirdview.currentRows.cells["price"].value反正如果不点击其他的控件就没有事.大家帮我想下,设计的东西太多了.郁闷.又是一个必须得解决的问题.
    大家有没有好的datagridview的单元格传事件的文章哦.哎.真是郁闷.突然跑出个问题来.
      

  4.   

    你这个 string price 和谁关联的?
      

  5.   


    怎么像是焦点的问题,事件贴全,取来了后怎么处理的,有没有写过EditingControlShowing事件
      

  6.   


    private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
            {
                if (this.dataGridView1.CurrentCell.ColumnIndex == 3)
                {
                    if (this.dataGridView1.CurrentRow.Cells["ItemNumber"].Value.ToString().Length == 0)
                    { return; }
                    if (e.Control is TextBox)
                    {
                        TextBox tb = e.Control as TextBox;
                        tb.TextChanged += new EventHandler(Quantity_TextChanged);
                    }
                }
            }        private void Quantity_TextChanged(object sender, EventArgs e)
            {
                double quantity, price, taxRate;
                double amount, amountCurrency;            try
                {
                    if (this.dataGridView1.CurrentCell.ColumnIndex == 3)
                    {
                        quantity = Convert.ToDouble(((TextBox)sender).Text);
                        price = Convert.ToDouble(this.dataGridView1.CurrentRow.Cells["Price"].Value);
                        taxRate = Convert.ToDouble(this.TaxRate.Text);                    if (quantity == 0 || price == 0 || taxRate == 0) return;
                         DataTable dt = myDCurrency.Currency_CurrencyID(Convert.ToInt32(this.CurrencyID.SelectedValue),DateTime.Today);
                        if (Convert.ToBoolean(dt.Rows[0]["TaxType"]) == false)
                        {
                            amountCurrency = myDVoucherReport.Voucher_CurrencyAmount(quantity * price / taxRate, num, computType);
                        }
                        else
                        {
                            amountCurrency = myDVoucherReport.Voucher_CurrencyAmount(quantity * price * taxRate, num, computType);
                        }
                        amount = myDVoucherReport.Voucher_CurrencyAmount(quantity * price, num, computType);                    this.dataGridView1.CurrentRow.Cells["Quantity"].Value = quantity;
                        this.dataGridView1.CurrentRow.Cells["Amount"].Value = amount;
                        this.dataGridView1.CurrentRow.Cells["AmountCurrency"].Value = amountCurrency;
                    }
    }
    里面有方法。但是第一次输入是没有问题的,但是点了其他的控件就成了那样的效果了.大家再想想哦.谢谢
      

  7.   

    this.dataGridView1.CurrentRow.Cells["Quantity"].Value = quantity;
    这行。
      

  8.   

    this.dataGridView1.CurrentRow.Cells["Quantity"].Value = quantity;
    是这句引起的问题,一来画蛇添足,没必要,二来由于你再次赋值,导致了再次触发了那个TextChanged事件,事件中触发事件,无限死循环啊,看看你的CPU使用率,肯定很高,焦点一移开,就不停地执行那个Quantity_TextChanged过程了,自然不让你输入别的值了。
      

  9.   

                if (dataGridView1.CurrentCell.ColumnIndex == 0)
                {
                    if (e.Control is TextBox)
                    {
                        TextBox tb = e.Control as TextBox;
                        tb.TextChanged += new EventHandler(tb_TextChanged);
                    }
                }
                else
                {
                    if (e.Control is TextBox)
                    {
                        TextBox tb = e.Control as TextBox;
                        tb.TextChanged -= new EventHandler(tb_TextChanged); // 要去掉,不然EditingControl会一直相应这个事件,即使是其他单元格
                    }
                }
      

  10.   

    还有EditingControl和单元格是两码事
      

  11.   

    各位老大,有没有最好的datagridview单元格附事件最好的最专业的办法哦.
    给个例子哦.我看好多资料都是在private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
            {
                if (this.dataGridView1.CurrentCell.ColumnIndex == 3)
                {
                    if (this.dataGridView1.CurrentRow.Cells["ItemNumber"].Value.ToString().Length == 0)
                    { return; }
                    if (e.Control is TextBox)
                    {
                        TextBox tb = e.Control as TextBox;
                        tb.TextChanged += new EventHandler(Quantity_TextChanged);
                    }
                }
            }
    是不是一开始就是个错误哦.
      

  12.   

    DataGridView 控件一次承载一个编辑控件,并且只要单元格类型在编辑之间不发生更改,就重新使用该编辑控件。将事件处理程序附加到编辑控件时,因此必须采取预防措施以避免多次附加同一处理程序。要避免出现此问题,请在将处理程序附加到事件之前从该事件中移除该处理程序。如果处理程序已附加到事件,这样将防止重复,但在其他情况下将不起任何作用。有关更多信息,请参见 DataGridViewComboBoxEditingControl 类概述中的示例代码。这个是MSDN上的说明。很明白了已经。
      

  13.   

    http://msdn.microsoft.com/zh-cn/library/system.windows.forms.datagridview.editingcontrolshowing.aspx自己去看,解决办法和示例代码都有。
      

  14.   

    是这句引起的问题,一来画蛇添足,没必要,二来由于你再次赋值,导致了再次触发了那个TextChanged事件,事件中触发事件,无限死循环啊,看看你的CPU使用率,肯定很高,焦点一移开,就不停地执行那个Quantity_TextChanged过程了,自然不让你输入别的值了顶了
      

  15.   


    private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
            {
                if (e.ColumnIndex == 3)
                {
                    double quantity, price, taxRate;
                    double amount, amountCurrency;                try
                    {
                        quantity = Convert.ToDouble(this.dataGridView1.Rows[e.RowIndex].Cells["Quantity"].EditedFormattedValue);
                        price = Convert.ToDouble(this.dataGridView1.Rows[e.RowIndex].Cells["Price"].Value);
                        taxRate = Convert.ToDouble(this.TaxRate.Text);                    if (quantity == 0 || price == 0 || taxRate == 0) return;
                        DataTable dt = myDCurrency.Currency_CurrencyID(Convert.ToInt32(this.CurrencyID.SelectedValue), DateTime.Today);
                        if (Convert.ToBoolean(dt.Rows[0]["TaxType"]) == false)
                        {
                            amountCurrency = myDVoucherReport.Voucher_CurrencyAmount(quantity * price / taxRate, num, computType);
                        }
                        else
                        {
                            amountCurrency = myDVoucherReport.Voucher_CurrencyAmount(quantity * price * taxRate, num, computType);
                        }
                        amount = myDVoucherReport.Voucher_CurrencyAmount(quantity * price, num, computType);                    //this.dataGridView1.CurrentRow.Cells["Quantity"].Value = quantity;
                        this.dataGridView1.Rows[e.RowIndex].Cells["Amount"].Value = amount;
                        this.dataGridView1.Rows[e.RowIndex].Cells["AmountCurrency"].Value = amountCurrency;                }
                    catch
                    {
                        return;
                    }
                }
            }哎,研究了一天一夜,把代码写在这个下面比较可以.