开发者

hooking up events to vertical scroll bar upper arrows and down arrows in data grid view using c#

开发者 https://www.devze.com 2023-04-12 21:14 出处:网络
I have a datagrid view like this....in below image well thats works fine... I nee开发者_高级运维d to hook up an event in vertical side bar ..

I have a datagrid view like this....in below image well thats works fine...

I nee开发者_高级运维d to hook up an event in vertical side bar ..

i mean if i click on upper arrow in the scroll bar i want to do something ...

If i click on the down arrow in that scroll bar , i want to do something...

To be more specific i want to get the id of first upper record when i click on upper arrow in vertical scroll bar..

How can i do this... , I am using winforms

would any one pls help on this....

Many thanks in advance

hooking up events to vertical scroll bar upper arrows and down arrows in data grid view using c#

I have found this but i dont know how to implement this in my page

 using System.Reflection;
 using System.Windows.Forms;

bool addScrollListener(DataGridView dgv)
{
bool ret = false;

Type t = dgv.GetType();
PropertyInfo pi = t.GetProperty("VerticalScrollBar", BindingFlags.Instance | BindingFlags.NonPublic);
ScrollBar s = null;

if (pi != null)
    s = pi.GetValue(dgv, null) as ScrollBar;

if (s != null)
{
    s.Scroll += new ScrollEventHandler(s_Scroll);
    ret = true;
}

return ret;
}

 void s_Scroll(object sender, ScrollEventArgs e)
 {
 // Hander goes here..
 }

I have done like this...

private void s_Scroll(object sender, ScrollEventArgs e)
{
    if (e.ScrollOrientation == ScrollOrientation.VerticalScroll)
    {
        if (e.Type == ScrollEventType.ThumbPosition)
        {
            if (e.Type == ScrollEventType.SmallIncrement)
            {

                int i = dgvMembers.FirstDisplayedScrollingRowIndex;
                int idemebers =Convert.ToInt32(dgvMembers.Rows[i].Cells["Id"].Value.ToString());
                getMemberInfo(i, idemebers);

            }
            if (e.Type == ScrollEventType.SmallDecrement)
            {
                int i = dgvMembers.FirstDisplayedScrollingRowIndex;
                int idemebers = Convert.ToInt32(dgvMembers.Rows[i].Cells["Id"].Value.ToString());
                getMemberInfo(i, idemebers);
            }
        }
    }            
} 

but this event does not fire s.Scroll += new ScrollEventHandler(s_Scroll); it does not goes into the this event ...

would any one pls help on this...


You should be able to use the code you have posted. All you need to do is call addScrollListener somewhere (for example in your constructor after InitializeComponent)

  public Form1()
  {
     InitializeComponent();
     // Replace dataGridView1 with the name of your DataGridView
     addScrollListener(dataGridView1);  
  }

  // addScrollListener code goes here
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号