C# .NET - Use Button Dropdown list in data grid view in windows forms

Asked By Jipin M on 17-May-11 01:17 AM
Hi all...

 How to use a buton and dropdown list in a datagridview control for each row, and get a value from the row on a button click. Also the dropdownlist value is selected according to a database field when the data binding.

Regards.......
Ravi S replied to Jipin M on 17-May-11 01:20 AM
Hi

here are some example s

refer these links...you will find good examples
http://msdn.microsoft.com/en-us/library/aa480727.aspx
http://msdn.microsoft.com/en-us/library/ms178294%28v=vs.80%29.aspx
Reena Jain replied to Jipin M on 17-May-11 01:22 AM
hi,

To Add dropdownlist and button here is the code process for you

  1. In your Windows Application project, add a reference to the DataGridViewAutoFilter.dll assembly.
  2. Add a DataGridView control to a form and bind data to it using the Choose Data Source task on the control's smart tag.
  3. After the columns have been generated, on the control's smart tag, click Edit Columns.
  4. In the Edit Columns dialog box, select a column.
  5. In the Properties window in the dialog box, select the ColumnType property and choose DataGridViewAutoFilterTextBoxColumn from the drop-down list.
  6. Repeat steps 4 and 5 for all columns that you want to use the AutoFilter feature with.
  7. After you have completed column configuration, run your application and confirm that drop-down buttons appear in the headers of the columns you selected. here is a sample of the Edit Columns dialog box being used to set the column type to DataGridViewAutoFilterTextBoxColumn.

Fig 2. The Edit Columns dialog box with the ColumnType property set to DataGridViewAutoFilterTextBoxColumn.


Hope this will help you
TSN ... replied to Jipin M on 17-May-11 01:25 AM
hi..

DataGridView Combo column (extended combobox) Download http://rustemsoft.com/DataGridViewColumnsTrial.zip

The DataGridViewComboColumn contains combobox for a DataGridView on your .NET form. The Combo column is not just a dropdown combobox, which appears when a DataGridView cell becomes the current cell. The .Net DataGridView Combo Column control has the following attractive features:

This DataGridView Combo column is not just a dropdown combobox, which appears when a DataGridView cell becomes the current cell. This DataGridView Combo Column gives you ability to instantly update dropdown values with a really simple and friendly user interface. When you click the combo button a dropdown multiple columns grid of its list values will be shown below the combo. You can update values,and insert and delete rows into the dictionary DataGridView.

You can set its DataSource, DisplayMember, and ValueMember to bind the Combo to a foreign table

The control gives an ability to get a nesting combo box that filters values from a related child table. In a dictionary grid, you can view and edit related data in a child table. In your database a Master table has a one-to-many relationship with a Child table; so for each row of the Master table in Dictionary grid, you or your customer can view and edit the related


rows of the Child table in a dictionary grid. For this case we have to define two string arrays with key fields' names MasterFields and ChildFields. To get the filtering we must identify Master and Child tables' key fields. These fields' names in both arrays must have the same order sequence.

Syntax
DataGridViewComboColumn()

Some Properties

box - Combobox object in selected cell. Gets the hosted box control that is an overridden instance of the ComboBox control.

box.DataSource - a source for DataGridView values list as System.Data.DataTable

box.DisplayMember - field to display in combo as String (name of table column)

box.ValueMember - field with values, which binds to combo as String (name of table column). Specify the contents of the ValueMember property in cases where you bind data.

box.DisplayMode - Identifies what kind of data you would like to see in whole DataGridView customized column, as DataGridViewColumns.DisplayModes. You may choose the following values:
ShowDisplayMember - default. DisplayMember will be shown in whole column
ShowValueMember - ValueMember will be shown in whole column
ShowValueMember_and_DisplayMember - ValueMember + DisplayMember will be shown together in a column

box.allDictionaryColumns - The property identifies how many columns you need to see in the called Dictionary grid, as DataGridViewColumns.FieldsDisplayType(default is DisplayMember_ValueMember_only)
You may set the following values:
DisplayMember_ValueMember_only - default. DisplayMember and/or ValueMember fields will be shown in your drop-down Dictionary grid.
allFields - all related child table's fields will be shown in your drop-down Dictionary grid.
allFields_ExceptRelationKey - all related child table's fields will be shown in your Dictionary grid except relation key fields.

Also you can leave the allDictionaryColumns parameter (define it as null in C# and C++ code) and specify your own columns for the Dictionary DataGridView. Please see our samples to learn how to do that.

// Set DataGridView Combo Column for CarID field   
DataGridViewComboColumn ColumnCar = new DataGridViewComboColumn();  
// DataGridView Combo ValueMember field name is "CarID"  
// DataGridView Combo DisplayMember field name is "Car"  
ColumnCar.DataPropertyName = "CarID";  
ColumnCar.HeaderText = "Car Name";  
ColumnCar.Width = 80;  
// Bind ColumnCar to Cars table  
ColumnCar.box.DataSource = ds.Tables["Cars"];  
ColumnCar.box.ValueMember = "CarID";  
ColumnCar.box.DisplayMember = "Car";  
// Add ColumnCar onto DataGridView layout  
DataGridView1.Columns.Add(ColumnCar);  


hope this helps you...