I want to show a DataGridView with a ComboBox column that looks like a DataGridViewTextBoxColumn.
In DataGridView I have the DataGridViewTextBoxColumn displayed and when the user sets Focus on a cell i开发者_开发问答n this column, the cell should be changed to ComboBox.
I don't know which function has to be overriden.
In DataGridTextBoxColumn there is the function Edit, can I can draw my combobox during this function?
Unless I'm missing something - you should be able to simply use the DataGridViewComboBoxColumn column type.
Depending on how you are adding your columns you either chose this type in the Type drop down in the Add Column dialog or add it programarically like so:
DataGridViewComboBoxColumn col = new DataGridViewComboBoxColumn();
dataGridView1.Columns.Add(col);
To achieve the effect you are after of a combobox that looks like a textbox until you edit it you set the DataGridViewComboBoxColumn DisplayStyle property to be Nothing:
List<string> names = new List<string> { "Joe", "Sally", "Kate" };
DataGridViewComboBoxColumn col = new DataGridViewComboBoxColumn();
col.DataSource = names;
col.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing;
dataGridView1.Columns.Add(col);
You can also access the underlying control of a DataGridView cell through the EditingControlShowing event.
精彩评论