TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Deeraj S
NA
145
12.4k
How to bind different items to each cells of combobox column in datagr
Sep 23 2020 4:29 AM
How to bind different items to each row cell of particular combobox column in datagridview
Reply
Answers (
1
)
2
Rajanikant Hawaldar
32
38.8k
438.6k
Sep 23 2020 4:43 AM
hello deerj here is sample code,
using
System.Windows.Forms;
namespace
BindDifferentItemsInEachCellofGridWithComboType
{
public
partial
class
Form1 : Form
{
private
DataGridView DataGridViewObj =
new
DataGridView();
public
Form1()
{
InitializeComponent();
DataGridViewComboBoxColumn dataGridViewComboBoxColumn =
new
DataGridViewComboBoxColumn();
dataGridViewComboBoxColumn.HeaderText =
"Different Items Combobox"
;
DataGridViewObj.Columns.Add(dataGridViewComboBoxColumn);
this
.Controls.Add(DataGridViewObj);
//Binding combobox particuler cell
setCellComboBoxItems(DataGridViewObj,0,0,
new
object
[] {
"C#"
,
"Python"
,
"VB"
});
DataGridViewObj.Rows.Add();
setCellComboBoxItems(DataGridViewObj,0,0,
new
object
[] {
"PHP"
,
"C++"
});
}
private
void
setCellComboBoxItems(DataGridView dataGridViewObj,
int
rowIndex,
int
colIndex,
object
[] itemsToBindCell)
{
DataGridViewComboBoxCell dgvcbCell = (DataGridViewComboBoxCell)dataGridViewObj.Rows[rowIndex].Cells[colIndex];
dgvcbCell.Items.Clear();
foreach
(
object
itemToAdd
in
itemsToBindCell)
{
dgvcbCell.Items.Add(itemToAdd);
}
}
}
}
Accepted Answer
How to disable datagridview sorting
How to develop web browsers