Click here to Skip to main content
15,905,612 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted

1 solution

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900