How Bad Can it Get?

  • Thread starter Thread starter J
  • Start date Start date
J

J

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/quicks...to/doc/WinForms/WinFormsOwnerDrawListBox.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?
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? From what I can see, and am most likely
wrong, one has to reference the dataset directly? If so, bad design, MS.
The listbox has the text to be drawn, it should have been passed to the
method.

Bitch session over...
 
J said:
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/quickstart/aspplus/default.aspx?url=
%2fquickstart%2fhowto%2fdoc%2fWinForms%2fWinFormsOwnerDrawListBox
.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.
 
Hi,
Unfortunately bad code examples seem to be a habit at ms. Have seen
many of those in MSDN. code with errors, not working and with memory
leaks (I am a cpp programmer). Otherwise most of the time they are
usefull in some way.

Peyman Zehtab-Fard
 
Back
Top