OwnerDraw Listbox and attached textbox

B

Bob Dankert

I am trying to attach a textbox to an ownerdrawn listbox. The listbox works
great. I add the textbox to the controls of the listbox and set the
location of the textbox. The problem is keeping the textbox in the right
place, because the listbox always draws on top of it during various
scrolling events. In an attempt to remedy this, I have an event that fires
on the WM_PAINT and WM_VSCROLL of the listbox which re-sets the location of
the child textbox (ocassionally the Y-position will become in the tens of
thousands) and refreshs the child textbox.

Currently, when I drag the scroll bar up and down it works perfectly. When
I scroll up or down a page (click the scroll bar above or below the bar) it
moves the textbox down/up a page (leaves it in the same position) which it
should not be doing. Also, if I click the scroll bar arrows to scroll it
one item at a time, I get double textboxes (the pre-scroll text box does not
go away, and the after-scroll text box comes back).

I have been working on this for tens of hours and can not come up with a
good way to attach the textbox to the listbox so that it scroll in unison
with the listbox. Any help is greatly appreciated.

Bob Dankert
 
R

Rhett Gong [MSFT]

Hi Bob,
From your description, you are trying to attach a textbox to an listbox(ownerdrawn). The listbox is ok, but
when you click the arrow to scroll, you get "two" textboxes in the listbox.

I noticed that you had post another message titled "WM_ERASEBKGND - which item?". From the context, it
seems that you have got an easy workaround for this problem, haven't you? Please feel free to let us know
if there is any misunderstanding or you still need assist on this issue. Thanks.

Have a nice day!
Rhett Gong [MSFT]
Microsoft Online Partner Support

This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only. Thanks.
 
B

Bob Dankert

Thanks for the reply. Actually, that does not help at all, it is kind of
complicated to explain. When I attach the textbox to the listbox and
scroll, it seems as though an event is fired out of order because if I
scroll down, it seems as though it moves the textbox after the listbox items
are repositioned, which then requires the listbox item that was beneath the
textbox to be re-drawn.

Basically, I am trying to find a smooth way to attach a textbox at some
position to an owner-draw listbox. If needed, I can paste some very small,
lightweight code to replicate the problem I am having.

Thanks,

Bob Dankert
Rhett Gong said:
Hi Bob,
From your description, you are trying to attach a textbox to an
listbox(ownerdrawn). The listbox is ok, but
when you click the arrow to scroll, you get "two" textboxes in the listbox.

I noticed that you had post another message titled "WM_ERASEBKGND - which item?". From the context, it
seems that you have got an easy workaround for this problem, haven't you?
Please feel free to let us know
if there is any misunderstanding or you still need assist on this issue. Thanks.

Have a nice day!
Rhett Gong [MSFT]
Microsoft Online Partner Support

This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only. Thanks.
 
R

Rhett Gong [MSFT]

If it is complicated to explain, please send a simple repro sample to me. Just remove the online from my
email address.

Thanks.
Rhett Gong [MSFT]
Microsoft Online Partner Support

This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only. Thanks.
 
R

Rhett Gong [MSFT]

Hi Bob,
I have got your repro code. However, I still can't figure out what your problem is since no matter I drag the
scroll bar up and down, click the scroll bar above or below, or click the scroll bar arrows (I also scroll it one
item at a time), it shows the same result---- the textbox was kept in Row2 in your sample.

Please reply this thread with detailed description for your problem. Thanks.
PS:I tested it with xpsp2beta and Visual Studio.net 2003, the .net framework version is 1.1.4322.573

Best regards,
Rhett Gong [MSFT]
Microsoft Online Partner Support

This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only. Thanks.
 
B

Bob Dankert

Here is an image which shows what I am exhibiting. I have tested this one
two boxes, each with VS.NET 2003, Windows XP Pro, SP1.
http://www.question-mark.net/images/multiplerows.bmp

This is after running the sample program and clicking the down arrow once.

I will try this on Windows 2000 and other operating systems as I can find
them, and let you know of the results.

Thanks,
Bob Dankert
Rhett Gong said:
Hi Bob,
I have got your repro code. However, I still can't figure out what your
problem is since no matter I drag the
scroll bar up and down, click the scroll bar above or below, or click the
scroll bar arrows (I also scroll it one
item at a time), it shows the same result---- the textbox was kept in Row2 in your sample.

Please reply this thread with detailed description for your problem. Thanks.
PS:I tested it with xpsp2beta and Visual Studio.net 2003, the .net
framework version is 1.1.4322.573
Best regards,
Rhett Gong [MSFT]
Microsoft Online Partner Support

This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only. Thanks.
 
R

Rhett Gong [MSFT]

I have tested it under 3 machines:
Windows XP sp1 tablet version ---- Everything appears correct.
Windows server 2003 ---- this is OK too.
Windows XP sp1 ----get the same image as you posted.
I am currently investigating this problem. I will update you later. Thanks!

Best regards,
Rhett Gong [MSFT]
Microsoft Online Partner Support

This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only. Thanks.
 
B

Bob Dankert

I tested it on Windows Server 2000 with SP3, everything appeared correct. I
would love to find a way to fix this on XPSP1 since this is the OS that most
of my clients are running.

Thanks,

Bob Dankert
 
R

Rhett Gong [MSFT]

Hi Bob,
I moved the following lines from "if (m.Msg == WM_VSCROLL || m.Msg == WM_PAINT){...}" to ODListBox_DrawItem(), the position is correct now. :)
//---------------------------------------------------------------------------------------
Rectangle rect;
foreach (TextBox ctrl in this.Controls)
{
// Always set the position to the second index
rect = this.GetItemRectangle(2);
ctrl.Location = rect.Location;
ctrl.Size = rect.Size;
ctrl.ResumeLayout(true);
ctrl.Refresh();
}
//----------------------------------------------------------------------------------------
Please let me know if it could work in your side.

Have a nice day!
Rhett Gong [MSFT]
Microsoft Online Partner Support

This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only. Thanks.
 
B

Bob Dankert

Well, that fixes the position problem, however it is still having an issue,
seemingly, drawing the textbox. An image of what I am referring to can be
found at:
http://www.question-mark.net/images/listboxproblem.bmp
This is after moving the code you mentioned after the if (e.index < 0)
return; lines of code. I'm not sure if you moved them to a slightly
different position or if you had better luck with this?

I will keep looking at it, but I thought I had tried this a while ago and
could not fix it.

Thanks,

Bob Dankert


Rhett Gong said:
Hi Bob,
I moved the following lines from "if (m.Msg == WM_VSCROLL || m.Msg ==
WM_PAINT){...}" to ODListBox_DrawItem(), the position is correct now. :)
//--------------------------------------------------------------------------
-------------
Rectangle rect;
foreach (TextBox ctrl in this.Controls)
{
// Always set the position to the second index
rect = this.GetItemRectangle(2);
ctrl.Location = rect.Location;
ctrl.Size = rect.Size;
ctrl.ResumeLayout(true);
ctrl.Refresh();
}
//--------------------------------------------------------------------------
--------------
Please let me know if it could work in your side.

Have a nice day!
Rhett Gong [MSFT]
Microsoft Online Partner Support

This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only. Thanks.
 
B

Bob Dankert

I changed the ctrl.Refresh() to ctrl.Invalidate and this works perfectly.
The one thing I noticed is that if you scroll down and up really fast, the
border would not be drawn on the textbox. However, I planned on setting the
border to none anyways, so this is not an issue.

I appreciate all the help and support in diagnosing this issue and getting
everything resolved.

Thanks a ton,

Bob Dankert
Rhett Gong said:
Hi Bob,
I moved the following lines from "if (m.Msg == WM_VSCROLL || m.Msg ==
WM_PAINT){...}" to ODListBox_DrawItem(), the position is correct now. :)
//--------------------------------------------------------------------------
-------------
Rectangle rect;
foreach (TextBox ctrl in this.Controls)
{
// Always set the position to the second index
rect = this.GetItemRectangle(2);
ctrl.Location = rect.Location;
ctrl.Size = rect.Size;
ctrl.ResumeLayout(true);
ctrl.Refresh();
}
//--------------------------------------------------------------------------
--------------
Please let me know if it could work in your side.

Have a nice day!
Rhett Gong [MSFT]
Microsoft Online Partner Support

This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only. Thanks.
 
R

Rhett Gong [MSFT]

I am glad to be of assistance. :)

Rhett Gong [MSFT]
Microsoft Online Partner Support

This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only. Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top