Solved

Add comboxbox column to datatable

Posted on 2009-07-09
3
245 Views
Last Modified: 2012-05-07
Hi,
I have a datagrdview bound by datatable.I add columns in this manner

column = New DataColumn(columnName, CType(drow("DataType"), Type))

need to make that column a combobox column
Any suggestions?
                             
0
Comment
Question by:RIAS
3 Comments
 
LVL 15

Assisted Solution

by:spprivate
spprivate earned 166 total points
ID: 24815016
Here is an example of adding combo box in grid view
http://www.c-sharpcorner.com/UploadFile/yougerthen/102122008053259AM/1.aspx
0
 
LVL 14

Assisted Solution

by:shahprabal
shahprabal earned 166 total points
ID: 24815066
Check the datagridview's column property, remove the automatically create columns option, create the columns manually. Here you can select the dropdown column to be added. Set the DataPropertyName to the data table column name and you are all set.
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcomboboxcolumn.aspx
 
0
 
LVL 4

Accepted Solution

by:
pepepaco earned 168 total points
ID: 24817688
remove the autogenerate columns property and add columns to the DataGridview in the same loop you add columns to your table. instead of add a DatagridViewColumn add a DataGridViewComboBoxColumn

//example from http://www.c-sharpcorner.com/UploadFile/yougerthen/102122008053259AM/1.aspx
// Create a new Combo Box Column
DataGridViewComboBoxColumn EmpIdColumn = new DataGridViewComboBoxColumn();
// Set the DataSource of EmpIdColumn as bellow
EmpIdColumn.DataSource = myDataSet.Tables[0];
// Set the ValueMember property as done bellow
EmpIdColumn.ValueMember = myDataSet.Tables[0].Columns[0].ColumnName.ToString();
// Set the DisplayMember property as follow
EmpIdColumn.DisplayMember = EmpIdColumn.ValueMember; g. Set the Header text column value:

Set the Header text column value:

There are two ways to do this, you can choose one of them:

EmpIdColumn.HeaderCell.Value = "EmployeeID";
or
EmpIdColumn.HeaderText = "EmployeeID";

Finally, add the combo box column to ordersGridView by doing so:

ordersGridView.Columns.Add(EmpIdColumn);


0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A short article about a problem I had getting the GPS LocationListener working.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question