使用 C# 将事件连接到数据网格视图中的垂直滚动条上箭头和下箭头
我有一个像这样的数据网格视图....在下图中,效果很好...
我需要在垂直侧栏中连接一个事件..
我的意思是,如果我单击滚动条中的上箭头,我想做的某事...
如果我单击该滚动条中的向下箭头,我想做某事...
更具体地说,当我单击垂直滚动条中的上箭头时,我想获取第一个上记录的ID。
我该如何做到这一点...,我正在使用 winforms,
请问有人可以吗?在此提供帮助....
提前非常感谢
我找到了这个,但我不知道如何在我的页面中实现这个
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..
}
我已经这样做了...
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);
}
}
}
}
但是这个事件不会触发 s.Scroll += new ScrollEventHandler(s_Scroll); 它不属于此事件...
有人可以帮忙吗...
I have a datagrid view like this....in below image well thats works fine...
I need 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
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...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该能够使用您发布的代码。您需要做的就是在某个地方调用
addScrollListener
(例如在InitializeComponent
之后的构造函数中)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 afterInitializeComponent
)