我winform开发的东西
开始在datagridview里面数据数字没有关系.
后来点了下其他的什么text控件.再去输入数字,它永远都能输入一个字.就是好像按住的shift全部选中一样.
我把editmode全部改了.都不知道出在什么地方.大家有经验,可以告诉下不?急死个人.
开始在datagridview里面数据数字没有关系.
后来点了下其他的什么text控件.再去输入数字,它永远都能输入一个字.就是好像按住的shift全部选中一样.
我把editmode全部改了.都不知道出在什么地方.大家有经验,可以告诉下不?急死个人.
或是你所说的text控件里有没有事件会影响到后面的输入!
能想到的就这些了!
就是取得另一个单元格的值string price=this.datagirdview.currentRows.cells["price"].value反正如果不点击其他的控件就没有事.大家帮我想下,设计的东西太多了.郁闷.又是一个必须得解决的问题.
大家有没有好的datagridview的单元格传事件的文章哦.哎.真是郁闷.突然跑出个问题来.
怎么像是焦点的问题,事件贴全,取来了后怎么处理的,有没有写过EditingControlShowing事件
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;
}
}
里面有方法。但是第一次输入是没有问题的,但是点了其他的控件就成了那样的效果了.大家再想想哦.谢谢
这行。
是这句引起的问题,一来画蛇添足,没必要,二来由于你再次赋值,导致了再次触发了那个TextChanged事件,事件中触发事件,无限死循环啊,看看你的CPU使用率,肯定很高,焦点一移开,就不停地执行那个Quantity_TextChanged过程了,自然不让你输入别的值了。
{
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会一直相应这个事件,即使是其他单元格
}
}
给个例子哦.我看好多资料都是在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 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;
}
}
}哎,研究了一天一夜,把代码写在这个下面比较可以.