You are hereForums & Blogs > Blogs
Register   |  Log In
 Richard Howells' Blog
Minimise

DataGridView – how to show a subset in a DropDownColumn

The standard approach is to add event handlers for CellBeginEdit and CellEndEdit. In CellBeginEdit a new datasources is bound to the dropdown and in CellEndEdit the binding is reversed. Here is a sample from the DataGridVew FAQ.

private void dataGridView1_CellBeginEdit(object sender,         DataGridViewCellCancelEventArgs e)

{

if (e.ColumnIndex == territoryComboBoxColumn.Index)

{

// Set the combobox cell datasource to the filtered BindingSource

DataGridViewComboBoxCell dgcb = (DataGridViewComboBoxCell)dataGridView1                        [e.ColumnIndex, e.RowIndex];

dgcb.DataSource = filteredTerritoriesBS;

 

// Filter the BindingSource based upon the region selected

this.filteredTerritoriesBS.Filter = "RegionID = " +

this.dataGridView1[e.ColumnIndex - 1, e.RowIndex].Value.ToString();

}

}

 

private...
Read More »

 Search
Minimise

Dynamisys is based near Swindon, Wiltshire, in the South West, and works with customers located throughout the UK. or telephone us on (+44) 1793 731225.

Learn more...
Next page(s)...

This page
Blogs

Previous Page(s)...
Forums