Hi,

i am creating a text box in listview item.
How I create is, I just take the location of the item and create a textbox on that location.
OnFocus over, I just take the textbox text and put it in that perticular listview item and hide
the textbox.

Now the problem is, since i am creating the textbox on a perticular location, when I scroll the lisview
the textbox remain in the same place (textbox does not get scrolled) and the data gets scrolled.

Solution what i thought is, whenver user wants to scroll or user clicks scroll bar, I
will hide the textbox.

But I could'n find the scroll bar click event. Or how do I find that user has clicked scroll bar ??

Is there any event where I can do this ??

Thanks.

Dani AI

Generated

— if switching to a DataGridView (as suggested) is not an option, the most reliable way to detect a user clicking or using the ListView scrollbar is to catch the native scroll messages the control receives and react there. Scrolling (thumb drag, track click, mouse wheel and many keyboard scrolls) produces WM_VSCROLL, WM_HSCROLL and WM_MOUSEWHEEL messages. Subclass the ListView, override WndProc, raise a small Scrolled event, and hide (or reposition) the temporary TextBox from that handler.

Example subclass that raises a Scrolled event:

public class ScrollingListView : ListView
{
    public event EventHandler Scrolled;

    private const int WM_VSCROLL = 0x0115;
    private const int WM_HSCROLL = 0x0114;
    private const int WM_MOUSEWHEEL = 0x020A;

    protected virtual void OnScrolled(EventArgs e) => Scrolled?.Invoke(this, e);

    protected override void WndProc(ref Message m)
    {
        base.WndProc(ref m); // let the control update positions (TopItem, etc.)
        if (m.Msg == WM_VSCROLL || m.Msg == WM_HSCROLL || m.Msg == WM_MOUSEWHEEL)
            OnScrolled(EventArgs.Empty);
    }
}

Wire the event to hide the editor or to recompute its location. Hiding is simplest and safest:

myListView.Scrolled += (s,e) =>
{
    if (activeTextBox != null && activeTextBox.Visible)
        activeTextBox.Hide();
};

If the editor must track the item instead of hiding, recompute the editor bounds after the scroll. For a whole-row edit use GetItemRect (call it after base.WndProc as shown). For precise subitem rectangles in Details view, use the native LVM_GETSUBITEMRECT (SendMessage) or compute X offset by summing column widths. Also handle WM_KEYDOWN/PageUp/PageDown and LostFocus as additional safeguards so edits are committed/hidden for keyboard scrolling. This approach keeps the custom grid and ensures the overlayed TextBox won't stay frozen while the data beneath it scrolls.

Recommended Answers

All 2 Replies

Perhaps a DataGridView and a DataGridViewTexBoxColumn could be more suitable for your purposes?

Thanks for the reply. But I can'nt go with any other grid as this is a customized grid used for long. And I have to go with this grid only.

Is there a way to achive this functionality with legacy win form listview ??

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.