Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/302.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在datagrid视图中未引发垂直滚动条事件_C#_.net_Winforms_Datagridview_Scrollbar - Fatal编程技术网

C# 在datagrid视图中未引发垂直滚动条事件

C# 在datagrid视图中未引发垂直滚动条事件,c#,.net,winforms,datagridview,scrollbar,C#,.net,Winforms,Datagridview,Scrollbar,我有一个像这样的数据网格视图…在下图中,这很好用 我需要在垂直侧栏上挂起一个事件 我的意思是,如果我点击滚动条上的上箭头,我想做点什么 更具体地说,当我点击垂直滚动条上的上箭头时,我想得到第一个上记录id的id using System.Reflection; using System.Windows.Forms; bool addScrollListener(DataGridView dgv) { bool ret = false; Type t = dgv.GetType

我有一个像这样的数据网格视图…在下图中,这很好用

我需要在垂直侧栏上挂起一个事件

我的意思是,如果我点击滚动条上的上箭头,我想做点什么

更具体地说,当我点击垂直滚动条上的上箭头时,我想得到第一个上记录id的id

 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;
}

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); // i want to the details of selected record into text boxes 

            }
            if (e.Type == ScrollEventType.SmallDecrement)
            {

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

            }
        }

    }   
} 
但这一事件并没有发生

s.Scroll += new ScrollEventHandler(s_Scroll);
它不会进入这个事件

有谁能帮上忙吗

非常感谢,请提前使用该活动

更具体地说,当我点击垂直滚动条上的上箭头时,我想得到第一个上记录id的id

DataGridView.Scroll
事件处理程序中,可以执行此操作(上箭头被视为小减量:

if (e.ScrollOrientation == ScrollOrientation.VerticalScroll
    && e.Type == ScrollEventType.SmallDecrement)
{
    int i = dgvMembers.FirstDisplayedScrollingRowIndex;
    // your code to process the first displayed row here
}

您不能使用
dgv.Scroll+=新的ScrollEventHandler(s_Scroll)