winform下dataGridView RowPrePaint事件 死循环的问题
如题。该问题该如何解决呢? --------------------编程问答-------------------- 晕,你不让他死啊。 --------------------编程问答--------------------没让他死呀,代码如下:
private void dgvTest_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
{
if (e.RowIndex >= dgvTest.Rows.Count - 1)
return;
if (dgvTest["No", e.RowIndex].Value.ToString() == "2")
{
dgvTest[Column2.Index, e.RowIndex] = new DataGridViewTextBoxCell();
dgvTest[Column2.Index, e.RowIndex].Value = "已删除";
}
} --------------------编程问答-------------------- 这...
你是嫌它死的慢啊.
事件不对,换别的事件 写修改value 的代码 --------------------编程问答--------------------
请教怎么事件不对呢?
我要实现的功能是:
当 No 列的值为2时,把以前的 Button 列替换成 TextBox列。 --------------------编程问答-------------------- 换CellEdit事件 --------------------编程问答--------------------
if ((string)dgvTest[1, e.RowIndex].Value == "2" && dgvTest[1, e.RowIndex].GetType() == typeof(DataGridViewButtonCell))
{
dgvTest[1, e.RowIndex] = new DataGridViewTextBoxCell();
dgvTest[1, e.RowIndex].Value = "2";
}
需要判断类型,避免死循环 --------------------编程问答--------------------
非常感谢,问题已经解决了。
但是不明白的是:
这个地方为什么要判断那列的类型呢? --------------------编程问答-------------------- 如果不判断类型,每次都会执行if里面的代码,从而触发重绘。
等同于循环没有出口,最后堆栈溢出。 --------------------编程问答-------------------- --------------------编程问答--------------------
也就是说 new DataGridViewTextBoxCell() 的时候还要触发下当前行的 RowPrePaint事件? --------------------编程问答-------------------- 嗯 --------------------编程问答--------------------
您好,我现在也遇到这样的问题了,想问一下具体判断什么类型?
我的代码如下
private void SGlistdataGrid_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
{
if (SGlistdataGrid["shenhe", e.RowIndex].Value != null && SGlistdataGrid["shenhe", e.RowIndex].Value.Equals("已过期失效"))
{
SGlistdataGrid["caozuo", e.RowIndex] = new DataGridViewTextBoxCell();
SGlistdataGrid["caozuo", e.RowIndex].Value = "此记录不可删除";
SGlistdataGrid["caozuo", e.RowIndex].ReadOnly = true;
}
}
补充:.NET技术 , C#