| | |
Remove multiple rows in Datagrid
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Sep 2007
Posts: 2
Reputation:
Solved Threads: 0
I have the following code in which it supposed to remove rows that have the first column checkboxes checked, but it only removes one row at a time.
If you have more than one checkbox checked, you have to click the command button each time to remove the row.
It seems that the logic is correct to remove multiple rows if more than one checkbox is checked, but it doesn't work.
If you have more than one checkbox checked, you have to click the command button each time to remove the row.
It seems that the logic is correct to remove multiple rows if more than one checkbox is checked, but it doesn't work.
VB.NET Syntax (Toggle Plain Text)
Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click For Each row As DataGridViewRow In DataGridView1.Rows If row.Cells("Delete").Value = True Then DataGridView1.Rows.Remove(row) End If Next End Sub
It worked with me..
vb Syntax (Toggle Plain Text)
'... for each m_row as System.Windows.Forms.DataGridViewRow in me.DataGridView1.Rows if m_row.Cells("Column1").Value=true then me.DataGridView1.Rows.Remove(m_row) end if next '...
•
•
Join Date: Aug 2009
Posts: 1
Reputation:
Solved Threads: 0
Hello,
The problem that you have is when you delete the row the datagrid reindexes it automatically so it can not acces correctly to the next row. So what you have to do is the opposite index counting with minus minus --:
I wish that help you!
David Lyons Garcia
The problem that you have is when you delete the row the datagrid reindexes it automatically so it can not acces correctly to the next row. So what you have to do is the opposite index counting with minus minus --:
vbnet Syntax (Toggle Plain Text)
for (int i = (dgVentaActiva.Rows.Count - 1); i >= 0; i --) { if ((Int32)dgVentaActiva["id_master", i].Value == lVendaElements[idElementVenda].elementIDTemporal) dgVentaActiva.Rows.RemoveAt(i); } lVendaElements.RemoveAt(idElementVenda);
I wish that help you!
David Lyons Garcia
Last edited by John A; Aug 9th, 2009 at 6:26 pm. Reason: removed fake signature, added code tags
![]() |
Other Threads in the VB.NET Forum
- Previous Thread: Please i need your advice on the Evoting System
- Next Thread: Adding controls to a two column TableLayoutPanel
| Thread Tools | Search this Thread |
.net .net2008 2008 access account add advanced application array basic beginner browser button buttons click code combo cpu cuesent data database datagrid datagridview date datetimepicker designer dissertation dissertations dissertationtopic employees excel exists fade filter forms generatetags html images input intel internet listview mobile module monitor mysql net number objects open panel pdf picturebox picturebox2 port position print printing printpreview problem regex reuse right-to-left save search searchvb.net select serial settings shutdown socket sqldatbase sqlserver storedprocedure survey temperature textbox timer timespan transparency txttoxmlconverter update user usercontol vb vb.net vb.netformclosing()eventpictureboxmessagebox vba vbnet vista visual visualbasic.net visualstudio.net visualstudio2008 web winforms wpf wrapingcode xml year





