Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
I want to view a datagridview textbox column containing values from different table. So that I can choose one of the value and other columns should filled according to those values.

I already use combo Box Column for the above case, its working but I want to press enter to move to next column, don't want to use tab key to move to next cell. and want to use tab key to move to next control in tab sequence.

I am using c#.net 2.0 and and .mdf file in sql express 2005.
Please help.
If possible then help me with some Project.
I will be very great full to you.
Posted

Sorry Sir,
is working on other column as it was but not working with combo box column. Combox column of Data grid view is not Listening any KeyDown Event. I didn't got my answer.
Code is for datagrid view to add combobox column and other column is:
<pre>
con.ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|Store.mdf;Integrated Security=True;User Instance=True;MultipleActiveResultSets=true;";
con.Open();
dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridView1.MultiSelect = false;
DataGridViewComboBoxColumn cmb = new DataGridViewComboBoxColumn();
SqlDataAdapter da = new SqlDataAdapter("Select SlNoFoodName,Unit,Quantity ,Total from KOT where KOTNo='"+textBox1.Text +"' and date= '"+dtp1+"'", con);
DataSet ds = new DataSet();
da.Fill(ds, "KOT");

dataGridView1.DataSource = ds.Tables[0];
SqlCommand cmd4 = new SqlCommand("select Code from FoodTable", con);
SqlDataReader dr4 = cmd4.ExecuteReader();
while (dr4.Read())
{
cmb.Items.Add(dr4[0].ToString());
}
dataGridView1.Columns.Insert(1, cmb);
dr4.Close();
con.Close();
</pre>

Please Help
Sorry for the delay.
Because I don't had the Internet Connetions.
Please Please
 
Share this answer
 
Hi Sourav972,

you can use the KeyDown event handler as follows :

private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
{
     if (e.KeyCode == Keys.Enter)
     {
         e.SuppressKeyPress = true;
         dataGridView1.CurrentCell = dataGridView1.CurrentRow.Cells[dataGridView1.CurrentCell.Index + 1];
     }
     else if (e.KeyCode == Keys.Tab)
     {
         e.SuppressKeyPress = true;
         NextControl.Select();
     }
}


where NextControl is the new control you want to select.

I hope this help,
Good Luck,
:)
 
Share this answer
 
I think you may have to use the KeyDown event and check for the ENTER key, then programmatically move to the next column. The KeyPress event only works on character keys.

http://msdn.microsoft.com/en-us/library/system.windows.forms.control.keydown.aspx[^]
 
Share this answer
 
Comments
[no name] 30-Apr-11 2:29am    
I alreadly tried the keypress, keydown and keyup events with the properties like keychar , keyvalue and so on. But i am not getting what I want.
Actually, I want to move to next cell in the same row using enter key, that works with TAB key.
Other cells are listining to keydown event but the combobox cell is not listning the event. and when I press enter it goes down to the next row and in the same column. I want same row and next column.
Please help
<code>
private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
e.SuppressKeyPress = true;
dataGridView1.CurrentCell = dataGridView1.CurrentRow.Cells[dataGridView1.CurrentCell.Index + 1];
}
else if (e.KeyCode == Keys.Tab)
{
e.SuppressKeyPress = true;
NextControl.Select();
}
}
</code>
dataGridView1.CurrentCell = dataGridView1.CurrentRow.Cells[dataGridView1.CurrentCell.Index + 1];
this line of code is which you want,
the meaning of the code is if you press Enter CurrentCell will move to next!!
try it!
GoodLuck!
-Wayne
 
Share this answer
 
Comments
Michael Waguih 30-Apr-11 5:08am    
What have you done more ... Only copying my 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