Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Add comboxbox column to datatable

Posted on 2009-07-09
3
Medium Priority
?
271 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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Six Sigma Control Plans

610 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