locked
c# Lisview scroll click event RRS feed

  • Question

  • 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.

    Friday, May 17, 2013 5:48 AM

Answers

  • Perhaps you'll have to contact the 3rd party control vendor. Since Adnan's suggested code works fine for a regular ListView, I'm guessing that only the vendor will be able to tell you how/if that can be done with their control.

    ~~Bonnie Berent DeWitt [C# MVP]

    geek-goddess-bonnie.blogspot.com

    Sunday, May 19, 2013 4:47 PM

All replies

  • create a div inside listview and in that div create your textbox. and don't do it on location basis, find the div by ID, to create textbox, and to fetch value of textbox use Id.

    Faisal Ahmed Farooqui —————————— If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Friday, May 17, 2013 6:25 AM
  • Sorry, I have not mentioned, Actually this is a c# windows application.

    We can'nt use DIV which is as per my knowledge is for web application.

    Friday, May 17, 2013 6:36 AM
  • Override WndProc and see if you can find a message you can use to do what you want.
    Friday, May 17, 2013 7:40 AM
  • With the problem statement that you stated, I think you want to allow user to type right there in the list and the on lost focus, make it an item in the list.

    My suggestion is....

    Use DataGridView instead of listview, use binding source, so that it can recognize that a nw element is added in the grid. DataGridView allows to contain text and other kind of fields to make it editable.

    and you can make changes in the grid to look like list. I hope it will work.

    Best Of Luck.


    Faisal Ahmed Farooqui —————————— If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Friday, May 17, 2013 10:27 AM
  • hi Faisal,

    Thanks a lot for your answers. But my problem is that i can'nt go for any other grid. This is a custom grid that we use. So I have to do it with this grid only.

    Is there a way to get this functionality done with legacy windows listview ??

    Thanks again,

    Friday, May 17, 2013 3:25 PM
  • "Is there a way to get this functionality done with legacy windows listview ??"

    Hide the textbox when the control scrolls.

    Friday, May 17, 2013 3:32 PM
  • using System.Windows.Forms;
    
    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
                
                // test
                MyListView listView = new MyListView();
                listView.Dock = DockStyle.Fill;
                listView.OnScroll += new ScrollEventHandler(listView_OnScroll);
                listView.Parent = this;
    
                for (int i = 0; i < 100; i++)
                {
                    listView.Items.Add("Test item " + i.ToString()); 
                }
    
            }
    
            void listView_OnScroll(object sender, ScrollEventArgs e)
            {
               
            }
        }
    
        public class MyListView : ListView
        {
            const int WM_HSCROLL = 0x114;
            const int WM_VSCROLL = 0x115;
            
            public event ScrollEventHandler OnScroll;
            protected virtual void OnScrollChanged(ScrollEventArgs e)
            {
                ScrollEventHandler handler = this.OnScroll;
                if (handler != null)
                {
                    handler(this, e);
                }
            }
    
            protected override void WndProc(ref Message m)
            {
                base.WndProc(ref m);
                if (m.Msg == WM_VSCROLL || m.Msg == WM_HSCROLL)
                {
                    OnScrollChanged(new ScrollEventArgs((ScrollEventType)(m.WParam.ToInt32() & 0xffff), 0));
                }
            }
        }
    }
    

    Friday, May 17, 2013 3:49 PM
  • Hi,

    I have a custom third party listview. I am inheriting it to a class, implemented some new functionality in it.

    I tried you code in that but it didn work. While debugging i found that "if (m.Msg == WM_VSCROLL || m.Msg == WM_HSCROLL)" in this if, the Msg is never equal to the specified constant. Hence it never triggers the event.

    I tried the same code in normal windows listview and it works fine.

    Do you have any idea where I am going wrong ?? The constraint it that i have to use the third party control only :-(

    Please let me know if you have any idea which can help me solve this problm.

    Thanks.

    Regards

    Sumitra

    Sunday, May 19, 2013 8:10 AM
  • Perhaps you'll have to contact the 3rd party control vendor. Since Adnan's suggested code works fine for a regular ListView, I'm guessing that only the vendor will be able to tell you how/if that can be done with their control.

    ~~Bonnie Berent DeWitt [C# MVP]

    geek-goddess-bonnie.blogspot.com

    Sunday, May 19, 2013 4:47 PM