Click here to Skip to main content
15,911,785 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello experts ,


here my problem .....i have data gridview in my form ...at 1st cell is normal textboxcell
but when user press enter key a combobox is popup with same item i want to set selected item as cell value can any buddy help me how to set selected item of combobx into datagridview cell


here is my code on datagriveiw key prees event


C#
if (e.KeyChar == 13)
   {
   if (dataGridView1.CurrentCell.ColumnIndex == 0)
      {
      this.cmb.Location = this.dataGridView1.GetCellDisplayRectangle(0, rowindex, true).Location;

      this.cmb.Show();
      this.dataGridView1.Controls.Add(cmb);
      cmb.Select();
      cmb.Focus();
      cmb.DroppedDown = true;
      GetNextControl(cmb, true).Focus();
      cmb.SelectedIndexChanged += new EventHandler(cmb_SelectedIndexChanged);
      e.Handled = true;
      }
   }


[edit]SHOUTING removed, formatting lined up - OriginalGriff[/edit]
Posted
Updated 13-Jan-19 2:50am
v2
Comments
OriginalGriff 2-Feb-12 9:58am    
DON'T SHOUT. Using all capitals is considered shouting on the internet, and rude (using all lower case is considered childish). Use proper capitalisation if you want to be taken seriously.

1 solution

Try this :

DataGridViewCell dgvc = (DataGridViewCell )dataGridView1[dataGridView1.CurrentCell.ColumnIndex,dataGridView1.CurrentCell.RowIndex];
dgvc.Value = cmb.SelectedText;
 
Share this answer
 

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