Is it possible to have both DataGridViewComboBoxCells and DataGridViewTextBoxCells in a single DataGridViewColumn? Or am I absolutely restricted to having one type per column?
相关问题
- Generic Generics in Managed C++
- How to Debug/Register a Permanent WMI Event Which
- 'System.Threading.ThreadAbortException' in
- Bulk update SQL Server C#
- Should I use static function in c# where many call
There is a weird solution for this.
By default create the column as TextBox.
Handle the cell click or cell enter event.
In the event if the ColumnIndex matches, Convert the column type to ComboBox and set the items.
Once the cell leave event fires from the respective column index, convert it back to textbox.
Dont forget to read the text from Combo before converting and set it to TextBox.
I know this is not apt solution but works.
I am eager to know if anyone has a better idea.
Questioner's EDIT:
Here was the code I ultimately wrote:
Also, when creating the column, I had to make sure it was a generic column; i.e. not a DataGridViewTextBoxColumn:
That way, I could change the CellTemplate later.