|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How to get the checked columns in DataGridViewhello guys,
I am having a DataGridView control. The first column is a checkbox column. The users can select the checkbox column. I need to loop through the grid rows and get the checked checkboxes and the rows numbers I don't know how to check if the first column checkbox is checked??? any help will be appreciated! Annie,
How did you populate your DataGridView, that can in thousand and one ways. Cor Show quoteHide quote "Annie" <myjunksandfor***@gmail.com> schreef in bericht news:458df628$1@dnews.tpgi.com.au... > hello guys, > > I am having a DataGridView control. > > The first column is a checkbox column. > > The users can select the checkbox column. I need to loop through the grid > rows and get > the checked checkboxes and the rows numbers > > I don't know how to check if the first column checkbox is checked??? > > any help will be appreciated! > Hi Annie,
you could try something like this , just susbstitute the name of your datagridview and the name or index of the cell that contains the checkbox. For n As Integer = 0 To Grid.Rows.Count - 1 If CBool(YourGrid.Rows(n).Cells("Selected").Value) = True Then Return True End If Next HTH, Martin Show quoteHide quote "Annie" <myjunksandfor***@gmail.com> wrote in message news:458df628$1@dnews.tpgi.com.au... > hello guys, > > I am having a DataGridView control. > > The first column is a checkbox column. > > The users can select the checkbox column. I need to loop through the grid > rows and get > the checked checkboxes and the rows numbers > > I don't know how to check if the first column checkbox is checked??? > > any help will be appreciated! > Just re-read your post, this should be closer to what you are after. Or you
could use a list of datagridviewrows and return that instead. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click For Each num As Integer In SelectedRows() Debug.Print(num.ToString) Next End Sub Private Function SelectedRows() As List(Of Integer) Dim list As New List(Of Integer) Dim Grid As DataGridView = Me.InvoicesControl1.InvoicesDataGridView For n As Integer = 0 To Grid.Rows.Count - 1 If CBool(Grid.Rows(n).Cells("Selected").Value) = True Then list.Add(n) End If Next Return list End Function HTH, Martin. Show quoteHide quote "Martin" <@ntlworld.com> wrote in message news:Intjh.23233$HV6.18553@newsfe1-gui.ntli.net... > Hi Annie, > > you could try something like this , just susbstitute the name of your > datagridview and the name or index of the cell that contains the checkbox. > > For n As Integer = 0 To Grid.Rows.Count - 1 > If CBool(YourGrid.Rows(n).Cells("Selected").Value) = True Then > Return True > End If > Next > > HTH, > > Martin > > > "Annie" <myjunksandfor***@gmail.com> wrote in message > news:458df628$1@dnews.tpgi.com.au... >> hello guys, >> >> I am having a DataGridView control. >> >> The first column is a checkbox column. >> >> The users can select the checkbox column. I need to loop through the grid >> rows and get >> the checked checkboxes and the rows numbers >> >> I don't know how to check if the first column checkbox is checked??? >> >> any help will be appreciated! >> > > Many thanks guys
that worked! Show quoteHide quote "Annie" <myjunksandfor***@gmail.com> wrote in message news:458df628$1@dnews.tpgi.com.au... > hello guys, > > I am having a DataGridView control. > > The first column is a checkbox column. > > The users can select the checkbox column. I need to loop through the grid > rows and get > the checked checkboxes and the rows numbers > > I don't know how to check if the first column checkbox is checked??? > > any help will be appreciated! > |
|||||||||||||||||||||||