Solved

Help with looping through Grid control and check ckeckbox

Posted on 2012-12-25
7
284 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
ID: 38720084
Use Rows

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

Expert Comment

by:sedgwick
ID: 38720105
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
ID: 38720125
Thanks, If I am not using the checkbox, How do I just highlight the row?
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 42

Accepted Solution

by:
sedgwick earned 500 total points
ID: 38720130
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
ID: 38720156
You can also set the row to Selected
0
 

Author Comment

by:vcharles
ID: 38720159
Thanks I will try them and get back to you.
0
 

Author Closing Comment

by:vcharles
ID: 38720211
Thank You!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Authentication of Web Services 3 53
VB.net/WinForms: adjust Screen Resolution 6 41
Need a complete list of ASP.NET page load events 3 28
Exit the loop 4 35
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

920 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