提问人:kenny 提问时间:4/9/2022 最后编辑:kenny 更新时间:4/9/2022 访问量:54
单击复选框并将所选行传递到另一个 datagridview
Click on checkbox and pass selected row to another datagridview
问:
当我从 datagridview 2 中选择超过 2 行时,我在更新或替换 datagridview 2 中找到的行时遇到问题
为了显示 datagriview 1 和 datagridview 2 中的信息,我使用数据源进行如下操作
数据网格视图 1:
Dim dtsm As New DataTable
dtsm = negPern.Listar_Personalxempresa(VGlobales.Base, Me.cboempresa.SelectedValue)
Me.dgvListadoMarcador.DataSource = dtsm
Me.dgvListadoMarcador.Columns(0).ReadOnly = False
数据网格视图 2:
Dim dts2 As New DataTable
dtsm = negPern.Listar_Personalxempresa(VGlobales.Base, Me.cboempresa.SelectedValue)
Me.dgv1.DataSource = dtsm
Me.dgv1.Columns(0).ReadOnly = False
这反映如下
更新按钮的过程是让用户选择 DGV 2 数据网格视图的任何行,如果它存在于数据网格视图 1 或 DGV 1 中,这将更新它
到目前为止,我已经设法通过使用以下代码逐个选择 1 来做到这一点
Dim rownu As DataRow = dtsm.NewRow()
Dim rowSelectedM As List(Of DataGridViewRow) = New List(Of DataGridViewRow)()
Try
For Each row As DataGridViewRow In dgv2.Rows
Dim cellSelecion As DataGridViewCheckBoxCell = TryCast(row.Cells("ELEGIR"), DataGridViewCheckBoxCell)
If Convert.ToBoolean(cellSelecion.Value) Then
rowSelectedM.Add(row)
End If
Next
For Each rown As DataGridViewRow In dgv1.Rows
If Convert.ToString(rown.Cells(3).Value).Equals(dgv2.CurrentRow.Cells(2).Value) Then
existeU = True
fila = rown.Cells(3).RowIndex
End If
Next
For Each row As DataGridViewRow In rowSelectedM
If existeU = True Then
If MessageBox.Show("ESTE REGISTRO YA EXISTE EN LA BASE MARCADOR N° FILA : " + " " + fila.ToString + " " + "DESEA ACTUALIZAR ?", "AUTONORT S.A.", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
'AQUI VA EL DTS
rownu("ACCION") = "U"
rownu("IDEMPRESA") = row.Cells(1).Value
rownu("IDCODIGOGENERAL") = row.Cells(2).Value
rownu("IDPLANILLA") = row.Cells(3).Value
rownu("FECHA_INICIOPLANILLA") = row.Cells(4).Value
rownu("A_MATERNO") = row.Cells(5).Value
rownu("A_PATERNO") = row.Cells(6).Value
rownu("NOMBRES") = row.Cells(7).Value
rownu("NRODOCUMENTO") = row.Cells(8).Value
rownu("LIQUIDADO") = row.Cells(9).Value
rownu("FECHA_INGRESO") = row.Cells(10).Value
rownu("FECHA_CESE") = row.Cells(11).Value
rownu("IDNACIONALIDAD") = row.Cells(12).Value
rownu("IDSUCURSAL") = row.Cells(13).Value
rownu("SUC") = row.Cells(14).Value
dtsm.Rows.RemoveAt(fila)
dtsm.Rows.InsertAt(rownu, fila)
dgv1.ClearSelection()
dgv1.FirstDisplayedScrollingRowIndex = dtsm.Rows.IndexOf(rownu)
dgv1.Focus()
End If
End If
Next
当我选择超过 2 行时,出现以下错误
删除第 2 行
理想的情况是替换 datagridview 的 2 个选定行,并添加操作 U = update
答: 暂无答案
评论
DataTable
Dim dtsm As New DataTable
Dim dtsm As DataTable = New DataTable
DataTable
DataTable
Dim dtsm = negPern.Listar_Personalxempresa(VGlobales.Base, Me.cboempresa.SelectedValue)
TryCast
TryCast
Nothing
Nothing
TryCast
DirectCast
Value