Problem in change values of datagridview using c#
Hello every one,
well i have one problem i have combo box which is bind from the database. when the user select from combo box after that focus should be cell number 3 of datagrid view i dont know which event should be used for it and what is the code for it. hope you understand what i want
thanks in Advance


Nilanka DharmadasaRank #1,875 · 794 reputationPosted Nov 11, 2009, 11:04 PM EST
What do you mean by cell 3?
Anyway, let's say you want to select cell with rowindex 2 and column index 3. And the name of datagridview is 'datagrid'.
Then try this code.
Naeem KhanRank #2,072 · 698 reputationPosted Nov 11, 2009, 10:09 PM EST
Naeem KhanRank #2,072 · 698 reputationPosted Nov 11, 2009, 11:15 PM EST
Nilanka DharmadasaRank #1,875 · 794 reputationPosted Nov 11, 2009, 11:39 PM EST
My code is not working for you?
If so paste you code here. Ill give you the exact solution. :)
Nilanka DharmadasaRank #1,875 · 794 reputationPosted Nov 11, 2009, 11:50 PM EST
//In your combo box selected index changed event, write this
datagrid.CurrentCell = datagrid.CurrentRow.Cells[3];
//Then do the calcualtion
datagrid.CurrentCell = datagrid.CurrentRow.Cells[5];
Naeem KhanRank #2,072 · 698 reputationPosted Nov 12, 2009, 12:30 AM EST
Kirtan PatelRank #292 · 8.6K reputationPosted Nov 12, 2009, 1:45 AM EST
you can not Directly Add new item to Combo box that is Bound to Some Database items
but you need to insert One Extra Row in Ds.Table[0] Which Will Contain this "Select party Name" before Binding ds.Table[0] to Combo Box
Code like Below
private void get_party_details()
{
cb_party_name.Items.Add("Select Party Name");
try
{
DataSet ds = new DataSet();
ds = gBL.show_party_details_name();
//Insert Row Here
DataRow r = new DataRow();
// Here Instad of r[3] use the Index of Column "Party Name" according to your Database Table Structure
r[3] = "Select Party Name";
ds.Tables[0].Rows.InsertAt(r, 0);
//After Adding New Row Now you can bind and It Will Show "Select Party Name in Combobox :)
cb_party_name.DataSource = ds.Tables[0];
cb_party_name.DisplayMember = "Party_Name";
}
catch (Exception)
{
//MessageBox.Show("Error!: " + ex.Message.ToString() + ". Please contact PSR Computers for Support");
}
if my answer Helps you then Check "Do you like this answer check box " :)
daniel raj2 reputationPosted Jun 20, 2010, 9:12 PM EDT