问题描述
我创建了一个自定义Windows窗体comboBox(editingControl)和一个自DataGridViewTextBoxCell继承的自定义dataGridViewCell.我的问题是,如果选择了另一个编辑控件,我的自定义comboBox会丢失列表项.
似乎每当我输入一个新的单元格或重新进入一个现有的单元格时,dataGridView.EditingControl都会重新初始化自身,因此会丢失先前的状态,然后再退出编辑模式并在另一个单元格中触发编辑模式
还有其他人遇到过这个问题吗?
-DA
I have created a custom Windows Form comboBox (editingControl) and a custom dataGridViewCell that inherits from DataGridViewTextBoxCell. My problem is my custom comboBox loses list items if another editing control is selected.
Seems that whenever I enter a new cell or reenter an existing cell the dataGridView.EditingControl re-initializes itself therefore losing the prior state before leaving edit mode and tiggering edit mode in another cell
Has anyone else had this issue?
-DA
推荐答案
public override void InitializeEditingControl(int rowIndex, object
initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle)
{
base.InitializeEditingControl(rowIndex, initialFormattedValue,
dataGridViewCellStyle);
TextBox ctl =
DataGridView.EditingControl as TextBox;
ctl.Text = (string)this.Value; // or convert to string if y''r using some other type
}
如果这不是问题,请共享您的代码.我也许可以提供帮助.
If this is not the issue, share your code. I might be able to help.
这篇关于自定义dataGridView.EditingControl丢失值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!