Solved

Add comboxbox column to datatable

Posted on 2009-07-09
3
229 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

A short article about problems I had with the new location API and permissions in Marshmallow
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

760 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now