Solved

Help with looping through Grid control and check ckeckbox

Posted on 2012-12-25
7
288 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

 
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

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…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

726 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