"J" <j> wrote in news:vo************@corp.supernews.com:
I think Microsoft purposely makes it difficult to learn their
products. Two examples of this are evident in the following MS
example.
http://samples.gotdotnet.com/quickst...ault.aspx?url=
%2fquickstart%2fhowto%2fdoc%2fWinForms%2fWinFormsO wnerDrawListBox
.aspx
One: The example code does not run. There is a reference to a
"listBoxBrushes", does not exist and causes an error. What kind
of quality control is this?
J,
The code on the URL you gave are just fragments. Scroll down to the
bottom of the page and click "View Source" to see all of the code.
If you have the QuickStarts installed on your system, the example is
in the folder:
C:\Program Files\Microsoft.NET\SDK\v1.1\QuickStart\howto\
samples\winforms\ownerdrawlistbox\cs
Two: The example does not show how to obtain the actual text
that is being drawn in the cell. How is one supposed to obtain
the cell text when the listbox datasource is a dataset?
Apply Occam's Razor. You get the text for the currently selected row
from the listbox itself. Here's a line of code from an example in
the help entry for DrawItemEventArgs:
// Draw the current item text based on the current Font
// and the custom brush settings.
e.Graphics.DrawString(listBox1.Items[e.Index].ToString(), e.Font,
myBrush, e.Bounds, StringFormat.GenericDefault);
Note the first parameter. DrawItemEventArgs (e) is passed to the
listbox's DrawItem event handler. The e.Index value tells DrawItem
which listbox row is being drawn. e.Index is used to get the text
from the listbox to draw.
Hope this helps.
Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/