Click here to Skip to main content
15,882,113 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi Everybody,
I am a c# beginner level. I have two problem. The problem is as follow.
First is. I want to know gridview's row selected with my value.Like that, when i click the button open a form1 that has a gridview, I will give a parameter like that ID 3. In gridview there are many row with ID as 1, 2, 3, 4, 5. When the form1 is opened, I want to auto select the row in gridview that has id 3.
Second is. In that form1, there are two textbox. That are ID and Sr. I can fill the data to that textboxs first time open form1 ID is 3 and Sr is 2.But when I double click the another row in gridview with ID 4 and Sr 1. When it fill the data to textbox, I get error message.
Error message is "This causes two bindings in collection to bind to the same property.Parameter name: binding".My code sample is as follow.
C#
private void Form1_Load(object sender, EventArgs e)
{
   //myParameterID is 3
   loadData(myParameterID);
}
private void LoadData(myParameterID)
 {
    bsData = new BindingSource();
    dtData = new DataTable();

   dtData = UtilityAccess.GetDataTable("Select ID, Sr From tbl1 Where ID = " + myParameterID , fillOptions.normal);
                
   bsData.DataSource = dtData;

   this.txtID.DataBindings.Add("Text", bsData, "ID", true);
   this.txtSr.DataBindings.Add("Text", bsData, "Sr";, true);
}
private void dgv_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
{
    //myParameterID is 4
   LoadData(myParameterID);
}
Posted
Updated 17-Oct-13 9:40am
v3

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