?
Solved

Add comboxbox column to datatable

Posted on 2009-07-09
3
Medium Priority
?
268 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 15

Assisted Solution

by:spprivate
spprivate earned 664 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 664 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 672 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
Six Sigma Control Plans
Progress

777 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