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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to Gray out text in ComboBox, ListView & ListBox if status in 2

Status
Not open for further replies.

atruhoo

Programmer
Jan 8, 2003
131
US
DB for record is inactive. Record still needs to be selectable but user wants to see by color change if is an inactive record. Any help or assistance to point me in right direction would be appreciated as this became a requirement for project after coding on application had begun, thus time for R&D is limited. Thanks in advance
 
Gotta love the scope creap. I don't beleive the combo/list boxes provided with the .Net framework provide this. You may want to grab a 3rd party control. Even then I don't know of any that can do a font change on each item. But you could put an 'inactive' icon next to them.

The other option, if it is just for a list box, would be to use a datagrid/flexgrid and format it to look like a standard list box. That would give you control over the row styles.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
You can do this with the ListView... Here's a snippet of code I have that does something very similar to what you're doing.

While oDR.Read
Dim ThisItem As New ListViewItem
ThisItem.Text = CType(oDR.Item("LogID"), String)
If oDR.Item("ErrorLogExclusion") = True Then
ThisItem.SubItems.Add("*")
ThisItem.BackColor = Color.Aqua
Else
ThisItem.BackColor = Color.White
ThisItem.SubItems.Add("")
End If
ThisItem.SubItems.Add(CType(oDR.Item("MsgSubj"), String))
ThisItem.SubItems.Add(CType(oDR.Item("ApplFName"), String))
ThisItem.SubItems.Add(CType(oDR.Item("ApplLName"), String))
ThisItem.SubItems.Add(CType(oDR.Item("SSN"), String))
lsvResults.Items.Add(ThisItem)
End While

In mine, as I'm building "ThisItem", I check a value in the database.. if it's true, I set the backgroud of just that row to Color.Aqua.

--
James
 
Thanks, Hadn't thought of that. However that may not solve all my issues since I am data binding my listviews with stored procs and not looping.......at least for now.
 
You can Owner Draw a combo box easily. There are many tutorials out there. You can change the back color, draw rectangles, fonts, images, etc.
 
Agree there are tutorials out there but as of yet I have not been able to find one that uses a stored proc to get the data and data bind each indiv record differently (i.e. Black = Active, Gray = Inactive) to a ComboBox/ListView based upon a field in the table (status field) without looping through each record. The above example works if doing that but since we are doing it more like below. If you know of an example that handles something like that I would greatly appreciate it as I may have missed something.

SetList(ListView, oMgr.ListParticipants, "Participants")

Public Sub SetList(ByVal List As ListBox, ByVal Items As Items, ByVal Tag As String)
Const cFUNCTION As String = cMODNAME + "SetList"
Try
List.DataSource = Nothing
With List
.BeginUpdate()
.DataSource = Items
.DisplayMember = "Description"
.ValueMember = "ID"
.SelectedItem = Nothing
.Tag = Tag
.EndUpdate()
End With
Catch ex As Exception
Dim oLog As New Logger(ex, cFUNCTION)
Finally
End Try
End Sub

Thanks again.

 
The example above is for a ListView. If you are using a ListView, use code similar to that of above.

If you do want to use a Combo Box, then owner draw it. The samples really dont need to have anything to do with a datasource. On DrawItem, cast the Item to a DataRowView and if the value of the Active column is false, then draw a gray font, else draw a black font.
 
Well, you could loop through all the items in the ListView after they have been bound and adjust the background color. That would require storing some sort of boolean value in the listview and hiding it (or not hiding it). But that way you could have the best of both worlds.

--
James
 
Just trying to think outside the box here. Could you bring back the color you want in your stored procedure as a calculated field, something like this:
Code:
Select Case When IsInactive Then IntegerColorForGray
            Else IntegerColorForWhite As BackGroundColor
Then perhaps you could bind your Color to BackGroundColor from the query. Sorry, I don't have any suggestions on the last part. Good Luck!

Have a great day!

j2consulting@yahoo.com
 
Just wanted to thank all that helped. Actually ended up doing looping through for my ListViews and then used an owner drawn combobox as well
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top