Delete row from Datagirdview
-
Hi There This is my first post, I need help I've a Datagridview filling from tbx and combobox, I want to put a Checkbox in each row (I don't how) so I want to delete a row checked from the datagridview Please help, I very rookie I'm doing this...
Public DRow As DataRow Public Carrito As New DataTable("Detalle") Sub Configuratabla() Dim DC0 As New DataColumn("Item", System.Type.GetType("System.Int64")) Dim DC1 As New DataColumn("Cantidad", System.Type.GetType("System.Int64")) Dim DC2 As New DataColumn("Detalle", System.Type.GetType("System.String")) Dim DC3 As New DataColumn("Valor", System.Type.GetType("System.Int64")) Dim DC4 As New DataColumn("Descuento", System.Type.GetType("System.Int64")) Dim DC5 As New DataColumn("Total", System.Type.GetType("System.Int64")) 'DC4.Expression = "cantidad * Valor " With Carrito.Columns .Add(DC0) .Add(DC1) .Add(DC2) .Add(DC3) .Add(DC4) .Add(DC5) End With GrillaDetalle.DataSource = Carrito End Sub DRow = Carrito.NewRow() DRow(0) = Carrito.Rows.Count + 1 'Item DRow(1) = CInt(TbxCan.Text) 'Cantidad DRow(2) = CbxPro.SelectedItem 'Detalle DRow(3) = Valor1 DRow(4) = CbxDes.SelectedItem 'Descuento DRow(5) = (CInt(TbxCan.Text) Carrito.Rows.Add(DRow)
:doh: -
Hi There This is my first post, I need help I've a Datagridview filling from tbx and combobox, I want to put a Checkbox in each row (I don't how) so I want to delete a row checked from the datagridview Please help, I very rookie I'm doing this...
Public DRow As DataRow Public Carrito As New DataTable("Detalle") Sub Configuratabla() Dim DC0 As New DataColumn("Item", System.Type.GetType("System.Int64")) Dim DC1 As New DataColumn("Cantidad", System.Type.GetType("System.Int64")) Dim DC2 As New DataColumn("Detalle", System.Type.GetType("System.String")) Dim DC3 As New DataColumn("Valor", System.Type.GetType("System.Int64")) Dim DC4 As New DataColumn("Descuento", System.Type.GetType("System.Int64")) Dim DC5 As New DataColumn("Total", System.Type.GetType("System.Int64")) 'DC4.Expression = "cantidad * Valor " With Carrito.Columns .Add(DC0) .Add(DC1) .Add(DC2) .Add(DC3) .Add(DC4) .Add(DC5) End With GrillaDetalle.DataSource = Carrito End Sub DRow = Carrito.NewRow() DRow(0) = Carrito.Rows.Count + 1 'Item DRow(1) = CInt(TbxCan.Text) 'Cantidad DRow(2) = CbxPro.SelectedItem 'Detalle DRow(3) = Valor1 DRow(4) = CbxDes.SelectedItem 'Descuento DRow(5) = (CInt(TbxCan.Text) Carrito.Rows.Add(DRow)
:doh:hi, i hope that this can help you : 1-to add checkboxcolumn: Dim mycolumn As New DataGridViewCheckBoxColumn mydatagridview.Columns.Insert(0, mycolumn) 2-to delete row: if mydatagridview.SelectedRows(i).Cells(0).Value=true then mydatagridview.rows.removeat(indexofmayrow) end if
Il principe ;)
-
Hi There This is my first post, I need help I've a Datagridview filling from tbx and combobox, I want to put a Checkbox in each row (I don't how) so I want to delete a row checked from the datagridview Please help, I very rookie I'm doing this...
Public DRow As DataRow Public Carrito As New DataTable("Detalle") Sub Configuratabla() Dim DC0 As New DataColumn("Item", System.Type.GetType("System.Int64")) Dim DC1 As New DataColumn("Cantidad", System.Type.GetType("System.Int64")) Dim DC2 As New DataColumn("Detalle", System.Type.GetType("System.String")) Dim DC3 As New DataColumn("Valor", System.Type.GetType("System.Int64")) Dim DC4 As New DataColumn("Descuento", System.Type.GetType("System.Int64")) Dim DC5 As New DataColumn("Total", System.Type.GetType("System.Int64")) 'DC4.Expression = "cantidad * Valor " With Carrito.Columns .Add(DC0) .Add(DC1) .Add(DC2) .Add(DC3) .Add(DC4) .Add(DC5) End With GrillaDetalle.DataSource = Carrito End Sub DRow = Carrito.NewRow() DRow(0) = Carrito.Rows.Count + 1 'Item DRow(1) = CInt(TbxCan.Text) 'Cantidad DRow(2) = CbxPro.SelectedItem 'Detalle DRow(3) = Valor1 DRow(4) = CbxDes.SelectedItem 'Descuento DRow(5) = (CInt(TbxCan.Text) Carrito.Rows.Add(DRow)
:doh:...or simply add another Column of Type Boolean to your DataTable Dim DC6 As New DataColumn("Delete", System.Type.GetType("System.Boolean")) .Add(DC6) '***initialize Column DRow(6) = false After Binding the DataTable to the DataGridView it will automatically create a CheckBoxColumn out of the DataType Boolean.