自定义dataGridView.EditingControl丢失值 [英] Custom dataGridView.EditingControl loses values

查看:138
本文介绍了自定义dataGridView.EditingControl丢失值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个自定义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

推荐答案

开始编辑时是否会出现问题?如果是这样,
检查您是否重写了DataGridViewTextBoxCell的InitializeEditingControl方法.您必须在其中初始化控件的值.
这是典型的实现方式

Does the problem occur when you begin an edit? If so,
Check if you have overridden the DataGridViewTextBoxCell''s InitializeEditingControl Method. You must initialize the control''s value inside it.
Here''s a typical implementation

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丢失值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆