Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CheckBoxListItem: Style Question

Status
Not open for further replies.

jkl

Programmer
May 16, 2001
83
US
I have a CheckBoxListItem listing all 50 states. I'm pulling out satet information from a sql db. I can get the data jsut fine, but what I want to do is change the color of the accompanying label if that state exists in the dataset. Is this possible?
 
Sure it is just loop through the dataset using a for loop and check to see if the two strings match if they do then set your label.backcolor to the color you want. That'l do donkey, that'l do
[bravo]
 
yeah i'm already looping through the checkboxlist.items(x), the thing is that i can't call out the label object for the checkboxlist item, to do anything to it.

here's my sub:

Private Sub checkItems(ByVal theCheck As CheckBoxList, ByVal compAr As Array)
Dim i, x As Integer
Dim chkStr, valStr As String

For i = 0 To (theCheck.Items.Count - 1)
chkStr = Trim(theCheck.Items(i).Text)
For x = 0 To UBound(compAr)
valStr = Trim(CStr(compAr(x)))
If chkStr = valStr Then
theCheck.Items(i).Selected = True
End If
Next
Next
End Sub

At the same time i'm setting the "selected = true", i want to change the label text color.
 
Goooood Morning Vietnam!!!
I'll be back need coffee. That'l do donkey, that'l do
[bravo]
 
Ok I am thinking this is harder than I thought. Agg to much thinking.
Sorry

There isn't a forecolor attribute per item basis. However I do have good news. There is an attribute collection for each item. You could try to play with this since I haven't worked with attribute collections to date I chose a different route. Change the text of the desired item to include basic html in it. Such as this. I have turned all non selected items to have italicised text.

dim i as integer
For i = 0 To (CheckBoxList1.Items.Count - 1)
If Not CheckBoxList1.Items(i).Selected Then
CheckBoxList1.Items(i).Text = &quot;<i>&quot; & CheckBoxList1.Items(i).Text & &quot;</i>&quot;

End If
Next


That should work splendidly That'l do donkey, that'l do
[bravo]
 
yeah i tried the changing text to include html method. it kinda works. the thing is that it won't change the text back, when i unselect the item and re-post.

i know it should be good enough that i'm doing the &quot;selected = true&quot;, but the end user is not so &quot;savvy&quot; so i'd like to be able to give him/her another visual clue that their selection was applied.

more digging...
 
Just add one these event handlers for the itemchanged event

Private Sub CheckBoxList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckBoxList1.SelectedIndexChanged

End Sub


Inside the event handler you'll need to do some string manipulation to get the original value.

The other option would be to rebind the control so that the original values from the database are shown. That'l do donkey, that'l do
[bravo]
 
the thing is i don't need the change to happen when the item is clicked, i need it to change after the list of items has been bound to the ds, and then the item comparison is made.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top