Click here to Skip to main content
15,881,281 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi all

I am trying to dynamically set the selected index of a combo box in data grid view. I tried with selected index, But it seems there is no selected index property of combo box in data grid view.
How can i set that?
And I bind this combo from db.

I think I explained ma ques in a right way.

Please help me

Thanks
Posted
Updated 19-May-21 22:57pm
Comments
Shanu2rick 13-Jul-13 2:54am    
Instead of using selected index why don't try DataGridViewCell value. Something like this
dataGridView.Rows[0].Cells[dataGridViewColumn.Name].Value = cellvalue;
Shafeequl 13-Jul-13 3:01am    
yes, you are right

Hi..

I Found out a solution to this,We can set the index of combo box in a data grid view as
C#
Datagridview1.Rows[yourrowIndex].cells["Your combobox column"].value=//set the value member here


it really works for me

Thanks
 
Share this answer
 
Comments
Member 11024178 12-Nov-16 2:02am    
It is not working
Member 11873034 22-Mar-17 2:58am    
It is not working
mungalim 28-Apr-17 14:45pm    
I need help for the same case like this ,,
But command

Datagridview1.Rows [yourrowIndex] .cells ["Your combobox column"]. Value = // set the value member here

Can not be on the way if the columns are shaped Combobox
If you want to work with the selectedIndex like in a comboBox
1. You have to add your Items to the comboBox element

C#
DataGridViewComboBoxColumn1.Items.Add("your Text ");
DataGridViewComboBoxColumn1.Items.Add("your Text1 ");
DataGridViewComboBoxColumn1.Items.Add("your Text2 ");


2. if you want to set the selectedIndex you have to do it like this
C#
int selectedIndex = 1
DataGridView1.Rows[yourrowIndex].cells["YourcomboBox column"].Value = DataGridViewComboBoxColumn1.Items[selectedIndex];


3 if you want to get the selectedIndex do it like this
C#
int selectedIndex = DataGridViewComboBoxColumn1.Items.IndexOf
(DataGridView1.Rows[yourrowIndex].cells["YourcomboBox column"].Value);


sorry for the delay and my englisch but i hope it will be helpfull
 
Share this answer
 
Comments
CHill60 2-Jan-18 11:45am    
"sorry for the delay" ... 4 years too late really.
Stick to answering new posts where the OP still needs help
Thanks a lot , this code works very well but i just changed selectedindex as 0

int selectedIndex = 0
DataGridView1.Rows[yourrowIndex].cells["YourcomboBox column"].Value = DataGridViewComboBoxColumn1.Items[selectedIndex];
 
Share this answer
 
Comments
CHill60 20-May-21 7:01am    
If you want to comment on a Solution then use the "Have a Question or Comment?" link next to it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900