Home > Net >  Solution: double-click datagridview1 c # a line selected data on datagridview2 add it to the same wi
Solution: double-click datagridview1 c # a line selected data on datagridview2 add it to the same wi

Time:10-02

Solution: double-click datagridview1 c # a line selected data on datagridview2 add it to the same window

CodePudding user response:

Directly write in CellDoubleClick events
The selected Row Clone () and then turn strong after
Datagridview2. Rows. It is ok to Add
This requires two DataGridview column definition is the same

CodePudding user response:

Upstairs said is a kind of method, you can also to data sources

CodePudding user response:

For winform and WPF, as long as the data sources are binding on the Add a DataRow, so the UI controls will automatically response, automatic line, more don't need programming operation UI controls,

CodePudding user response:

Private void datagridview1_CellClick (object sender, DataGridViewCellEventArgs e)
{
If (" e.R owIndex & gt; 1)
{
//equivalent to DataGridView
DataGridView view=sender as DataGridView;
If (the RowCount==0)
{
return;
}

//get selected single content
DataRow row=view. Rows [view. CurrentCell. RowIndex];


Datagridview2. Rows. The Add (row [0],... , a row [n]);
}
}

CodePudding user response:

reference 3 floor interacting in a professional developer response:
for winform and WPF, as long as the data sources are binding on the Add a DataRow, so the UI controls will automatically response, automatic line, more don't need programming operation UI controls,


Two-way binding, as long as change a data source, the DATAGRID datatable or dataset, binding the data source controls will follow to change data,

That it is as you say, what you mean

CodePudding user response:

I was using a stupid way, double-click dgv1, check the line number ID, perform binding operations such as Band2Dgv2 (int ID)
Band2Dgv2, query the database id corresponding records, and then bind to dgv2...

CodePudding user response:

Write wrong, is generally not band default is bind

CodePudding user response:

I also need to this code, if solved a favor also send this to me, thank you.

CodePudding user response:

I also need, solve the say ah,
  •  Tags:  
  • C#
  • Related