Solved

Help with looping through Grid control and check ckeckbox

Posted on 2012-12-25
7
283 Views
Last Modified: 2012-12-25
Hi,

I used the code below with a combobox to check checkboxes depending on utubeItemA (utubeItemA = 0,1,2 would cause checkboxes in first three rows to be checked)

How do I modify the code to do the same with the GridView control? Items is not a property of the GridView control.

  If utubeItemA IsNot Nothing Then
            For i As Integer = 0 To C1ItemA.Items.Count - 1
                If utubeItemA.Split(",").Contains(C1ItemA.Items(i).Text) Then
                    C1ItemA.Items(i).Selected = True
                    Dim CB As CheckBox = C1ItemA.Items(i).FindControl("CheckItemA")
                    CB.Checked = True
                End If
            Next
        End If

Thanks,

Victor
0
Comment
Question by:vcharles
  • 3
  • 2
  • 2
7 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
Use Rows

Grid.Rows(rowindex).Item(columnindex)
0
 
LVL 42

Expert Comment

by:sedgwick
Comment Utility
do something like:

 For i As Integer = 0 To gridView.Rows.Count - 1
            Dim cb As CheckBox = CType(gridView.Rows(i).FindControl("YourCheckBox"), CheckBox)
If utubeItemA.Split(",").Contains(gridView.Rows(i).Text) Then
            cb.Checked = True
  End If
        Next

Open in new window

0
 

Author Comment

by:vcharles
Comment Utility
Thanks, If I am not using the checkbox, How do I just highlight the row?
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 42

Accepted Solution

by:
sedgwick earned 500 total points
Comment Utility
Dim tokens As String() = utubeItemA.Split(",")

For Each row As DataGridViewRow In gridView.Rows
           If tokens.Contains(row.Text) Then
row.DefaultCellStyle.BackColor = Color.Red
  End If
Next

Open in new window

0
 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
You can also set the row to Selected
0
 

Author Comment

by:vcharles
Comment Utility
Thanks I will try them and get back to you.
0
 

Author Closing Comment

by:vcharles
Comment Utility
Thank You!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Need help with a query. 10 43
Windows Service to Receive TCP Packets 4 30
Code enhancement 5 12
Form design in vb.net 7 18
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now