Click here to Skip to main content
15,885,915 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello friends,
I have a DataGridView in my project. At first column as user press enter key, a ComboBox shows on that particular column which may contain many values. My problem is, I want to set the selected text of the ComboBox to that particular cell of the DataGridView. Can anyone help me with this? Right now it remains blank.

Thanks and regards, and sorry for poor English.
Rosy

[Edit - Took out all caps]
Posted
Updated 23-Jan-12 4:41am
v3
Comments
Kschuler 23-Jan-12 10:42am    
When you ask a question in all capital letters, it's like shouting. Please don't do it. I modified this question for you. Also, you say that it currently remains blank, can you post the code you are currently using that doesn't work?
rosyp 23-Jan-12 11:05am    
c = dataGridView1.CurrentCell.ColumnIndex;
r = dataGridView1.CurrentRow.Index;
if (dataGridView1.CurrentCell.ColumnIndex == 1 || dataGridView1.CurrentCell.ColumnIndex == 4)
{


if (e.KeyCode == Keys.Enter)
{
if (dataGridView1.Rows.Count > 1 || dataGridView1.CurrentCell.ColumnIndex != 0 || dataGridView1.CurrentCell.ColumnIndex != 5)
{
try
{
comboBox2.Visible = true;

this.comboBox2.Location = this.dataGridView1.GetCellDisplayRectangle(c, r, true).Location;
this.comboBox2.SelectedItem = this.dataGridView1.CurrentCell.Value;
this.comboBox2.Show();
this.comboBox2.SelectedItem = dataGridView1.CurrentCell.Value;
this.comboBox2.DroppedDown = true;
}
catch { }
}

}

}

}
rosyp 23-Jan-12 11:06am    
thanks
Dean Oliver 2-Feb-12 0:39am    
wpf or windows forms?

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