rahul s
rahul s

Reputation: 29

How to add combobox to second column in datagriview in c# wiforms?

How to add combobox to particular column in datagridview . I am add a combobox not( DataGridViewComboBoxColumn) .

Upvotes: 0

Views: 60

Answers (2)

Kostas Balis
Kostas Balis

Reputation: 122

Had a similar problem and handled it like this if my memory serves me correctly was a long time ago, not the best way of doing things but it worked.

private void mainGrid_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
{
     if (e.Column.Name != "Name of your combobox column")
     return;

     ComboBox cb = new ComboBox();
     cb.Bounds = e.CellBounds;
     cb.Font = ((mainGrid)sender).Font;
     cb.DataSource = "Your Datasource";
     cb.DisplayMember = "your display members";
     cb.ValueMember = "your value members";
     e.Control = cb;
}   

Upvotes: 0

Essigwurst
Essigwurst

Reputation: 555

You can only add this Types:

DataGridViewTextBoxColumn
DataGridViewLinkColumn
DataGridViewImageColumn
DataGridViewComboBoxColumn
DataGridViewCheckBoxColumn
DataGridViewButtonColumn

Why you want add a ComboBox?

Upvotes: 1

Related Questions