Dom said:
In some programs, I see that certain items in a listbox have been
grayed, to indicate that they are "there" but can not be chosen. This
is very helpful. Can you do this in CSharp? Is there a
lstMain.SelectedItem.Enabled?
I don't believe that the ListBox class supports this directly. I
haven't tried this, but I think you might be able to do it yourself by
deriving a new class from ListBox and in that class:
* Keep your own list of disabled items.
* Override OnDrawItem, and when drawing a disabled item, change the
font color before calling the base.OnDrawItem() method and then
restoring the font color to what it was before.
* Override WndProc, and before allowing a mouse click to be passed
to the base.WndProc() method, use the IndexFromPoint() method to
determine the item being clicked, and don't call the base.WndProc()
method if it's a disabled item.
* Override ProcessDialogKey, and just as you intercept mouse
events, intercept the keyboard events that might select a disabled item,
and do something to prevent that (IMHO the most user-friendly way would
be to repeat the keyboard events as necessary to skip over disabled
items, but there are a variety of ways you could choose to do this).
That's the general idea...I may have missed some specifics, or it may
turn out that there are better ways to do some of the above. As you can
see, it would be non-trivial to implement the behavior you want, but it
is probably less difficult to do that than to write a whole new listbox
class that does what you want.
Pete