Solved

Add comboxbox column to datatable

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

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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 …

730 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