BTW, it didn't do much harm to the tiny code snippet in your post (aside from the fact that theres a bogus smiley in there) but please use code tags when posting code.
EDIT: Oops: I just noticed that the code in the post I linked to is C#. But I think it shouldn't be too hard to translate it.
Last edited by Eri523; January 13th, 2011 at 08:12 PM.
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
There is, however, one fundamental difference to the C# implementation I linked to: It doesn't reside in a class derived from ListBox, instead it is an event handler attached to the ListBox control using the IDE. But unlike the habit of the IDE of placing the member implementation in the Form class' body inside the .h file, I moved it to a separate .cpp file. (This is the common way of doing that in native C++ and I definitely prefer it.) I chose this dfifferent way of implementing the drawing code because I don't know yet how to attach a derived class to an existing control. (I asked about that in post #11 of the thread I linked to but got no answer.)
As a consequence of not implementing it in a derived class I can't call the original ListBox::OnDrawItem() at the end of my function because it's a protected member and therefore not reachable except from a derived class. But I doubted the usefulness of that step anyway and apparently it works perfectly without it.
In order for this to work the DrawMode property of the list box needs to be set to OwnerDrawFixed in the IDE. The C# implementation does this in the derived class' constructor which I can't do here because there simply is no derived class.
Last edited by Eri523; January 14th, 2011 at 08:10 AM.
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
So there is no known way to use the following function to do it?
<code>
private: System::Void listBoxTest_DrawItem(System::Object^ sender, System::Windows::FormsrawItemEventArgs^ e)
{
// Place the code here
}
</code>
SG
EDIT: Stupid me but for some reason I cannot add code tags...
Last edited by scalpguy; January 15th, 2011 at 11:30 AM.
So there is no known way to use the following function to do it?
<code>
private: System::Void listBoxTest_DrawItem(System::Object^ sender, System::Windows::FormsrawItemEventArgs^ e)
{
// Place the code here
}
</code>
This is exactly the handler I implemented. With the private: in front of it and without the Form1:: qualification it is just the version placed in the form's .h file by the IDE. If you want to define it there, just leave the header as-is and use the function body I have posted without modification.
EDIT: Stupid me but for some reason I cannot add code tags...
You were pretty close: The code tags are [code] and [/code]. Or you can insert them in the Standard or Advanced Post Editor using the button depicted in the attached image.
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
For some reason my reply window looks a bit different. See attached file...
Hmmm... I've seen a screen shot like that from at least one other user. For me (using IE8) this has worked fine right from the start so I have no idea what could be the problem. If you actually set your options to either use the Standard or Advanced Post Editor, this looks like a case for the Feedback forum.
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.