c# - get data of checked row from 1 dataGrid to another datagrid, delete unchecked row from other datagrid -


I 2 DataGridView in WinForms dgv1 dgv2 dgv1 1 CheckBoxColumn, dgv2 few columns but no CheckBoxColumn. I need functionality that enables me, when I check the checkbox column, the data for that particular line should be selected and should go to DG2 2. This is how I put selected rows from dgv1 to dgv2. But if I cancel check (or uncock), then check the check box in DGV1 that the special line should be removed from DGV2. Help me fix this. I would be grateful to u friends, looking forward to this. :)

The idea here is my code datagridview6 = dgv1 and datagridview10 = dgv2

  private void DataGridView6_CellContentClick (object sender, DataGridViewCellEventArgs e) {dataGridView10.Visible = true if ( dataGridView6.CurrentCell.ColumnIndex == 7) {if (dataGridView6.CurrentCell.Value = null!) {bool checkstate = (bool) dataGridView6.CurrentCell.Value; If (checkset == incorrect) {dataGridView6.CurrentCell.Value = true; } Else {// here helps logic to delete unwanted lines of data; GridView6.CurrentCell.Value = false; Int j = int.Parse (dataGridView6.Rows [e.RowIndex]. Ostring ()); DataGridView10.Rows.Remove (dataGridView10.Rows [ja]); }} And {dataGridView6.CurrentCell.Value = true; DataGridView10.Rows.Instert (i); DataGridView10.Rows [i] .cs [1] .Value = DataGridView6.CurrentRow.Cells [2] .Value.ToString (); DataGridView10.Rows [i] .cel [2] .Value = DataGridView6.CurrentRow.Cells [3] .Value.ToString (); DataGridView10.Rows [i] .cel [3] .Value = DataGridView6.CurrentRow.Cells [5] .Value.ToString (); }}   

/ * This argument is being selected in the checked row in DGV2, but it is not working when it is removed.

Both data are not bound from the grid database,

You need to store RowIndex dgv1 at this time then the rows checked in dgv2 Adding that code to the dgv2 gridview of tags in the property now, you were created in dgv1.CurrentRow To store that new line index of the line Required.

Therefore, when the cell is unchecked, you can find the line connected to the DGV2 by using that line index.

We can not use row index to extract the line because the row index will be replaced if the line deleted from DGV2 will be changed. /// I have placed this code in the form load event. Dgv1.Rows.Add (wrong, "Nimesh", "Gujarat", "India", 1); Dgv1.Rows.Add (wrong, "light", "mp", "india", 2); Dgv1.Rows.Add (wrong, "Rohit", "Maharashtra", "India", 3); Dgv1.Rows.Add (false, "Jasbeer", "Punjab", "India", 4); Dgv1.Rows.Add (false, "Venkateswara", "Karnataka", "India", 5); Dgv1.Rows.Add (wrong, "Ronnie", "Delhi", "India", 6); /// We can not use the cell-change event because it will be executed after the cell end editing. /// We can not use Cell ContentClick Event Cause, when you double-click on multiple clicks or clicks /// So if we are using CellMouseUp Event Private Zero dgv1_CellMouseUp (Object Sender, DataGridViewCellMouseEventArgs E) return {if (dgv1.CurrentCell == blank); Dgv2.Visible = true; If (dgv1.CurrentCell.ColumnIndex == 0) {bool bValue = (bool) dgv1.CurrentCell.GetEditedFormattedValue (e.RowIndex, DataGridViewDataErrorContexts.CurrentCellChange); If (bValue) to {(int iRow = 0; iRow & LT; dgv2.Rows.Count; iRow ++) {if (dgv2.Rows [iRow] .Tag = null & amp ;! & amp; dgv2.Rows [IRow] .Tag. Par (dgv1.CurrentRow.Cells [4]. Price)) Return; } Int iNewRowIndex = dgv2.Rows.Add (); Dgv2.Rows [iNewRowIndex] .cel [0] .Value = dgv1.CurrentRow.Cells [1] .Value; Dgv2.Rows [iNewRowIndex] .cel [1] .Value = dgv1.CurrentRow.Cells [2]. value; Dgv2.Rows [iNewRowIndex] .cel [2] .Value = dgv1.CurrentRow.Cells [3]. value; Dgv2.Rows [iNewRowIndex]. Tag = dgv1.CurrentRow.Cells [4]. value; } Else {if (dgv1.CurrentRow.Cells [4] .Value = null!) To {(int iRow = 0; iRow & LT; dgv2.Rows.Count; iRow ++) {if (dgv2.Rows [iRow ] .ag! = Null & amp; dgv2.rows [iRow]. Tag.quals (DGV 1. current row seals [4]. Value) {dgv2.Rows.RemoveAt (iRow); break; }}}}}}

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -