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

listbox

Status
Not open for further replies.

christina

MIS
Nov 18, 2000
1
0
0
US
how do you change forecolor of an item(one item) in a listbox if a certain event takes place? like overdue books in a libary.
 
As far as I know It can't be done with the standard controls found in VB. You need to download a third party OCX and that will do the trick. I'm not sure but I bet that you can simulate a list box using a PictureBox and putting a label array inside of it. That way you can change each objects color, font, and background color. You can also set the mousemove event of the label in question and have it change the backcolor to blue and the forecolor to white to simulate the highlighting in a standard checkbox. Come to think of it that is a good project for me to work on, I'll let you know if it works, if you haven't found out already
DarkMercenary
darkmercenary44@earthlink.net

In the real world

As in dreams

Nothing is quite

What it seems

:Book of Counted Sorrows
 
Alright, I programed my own listbox, not a user control, sorry I don't know how to do that, but I submitted the tutorial to tek-tips and I hope that it helps, its called - How do I make a list box that can have different colors for each item in the list [PART1 and 2]. If they don't like it and don't post it email me at darkmercenary44@earthlink.net and I'll send you the word docs
DarkMercenary
darkmercenary44@earthlink.net

In the real world

As in dreams

Nothing is quite

What it seems

:Book of Counted Sorrows
 
Ok, the tutorial is up , its #9 a and b. Hope this helps you out
DarkMercenary
darkmercenary44@earthlink.net

In the real world

As in dreams

Nothing is quite

What it seems

:Book of Counted Sorrows
 
Declaring a global variable to transfer information between forms is the easiest, but certainly not the best way. This is especially true in complex projects.

Look for an alternative method using form properties:

1. Declare a Public Property in the First form with Property Get/Let procedure.
2. Initialize that variable

3. Accept that property of the first form in the initialize event of the second one.

4. Unload the first form.

Sample code below shows ho to transfer the contents of a textbox (txtOne) on frmOne to a label (lblTwo) on frmTwo.
The property is called FormValue and declared as a Variant. (adapt name and type to suit your needs)

Code for frmOne:

Option Explicit
Private m_vntFormValue As Variant

Public Property Get FormValue() As Variant
FormValue = m_vntFormValue
End Property

Public Property Let FormValue(fv As Variant)
m_vntFormValue = fv
End Property

Private Sub cmdTranfer_Click()
Me.FormValue = txtOne.TextLoad
frmTwofrmTwo.Show vbModal
Unload Me
End Sub

Code for frmTwo:

Option Explicit
Private Sub Form_Initialize()
lblTwo.Caption = frmOne.FormValue
End Sub

It does take some more time to code, but your value is protected against accidental modifications by other forms or modules, which results in huge savings at maintenance time. Of course this pre-supposes that your program will be subjected to maintenance at some future time, which is not un unreasable supposition...
robert
 

christina,
instead of using listbox to display your data, try making use of the MSFLEX GRID -- hope this works for you...
 
Sorry to all of you, I posted this reply in the wrong thread!
 
Can you use do an IF(condition) then listview.fontcolor = red. ??

Just an idea because I havent had to do it. But this is what Id try.

Hope it helps.

Jeremy
 
JeremyM,
No actually. It would be nice if you could. If you did it that way then you whould change the whole list box forecolor to red, but ChrisTina only wants to change one item in the list box to red. DarkMercenary
darkmercenary44@earthlink.net

In the real world
As in dreams
Nothing is quite
What it seems
:Book of Counted Sorrows
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top