using vscrollbar to scroll a xtragrid
Is it possible to handle xtragrid's
scrollbar via DevExpress.XtraEditors.VScrollBar
?
something like this:
private void vScrollBar1_ValueChanged(object开发者_开发问答 sender, EventArgs e)
{
gridView1.vScrollValue=VScrollBar1.Value;
}
Thanks in advance.
There is no way to do a smooth vertical scrolling with the xtragrid
. The scrolling is performed by rows.
To do that, use the Scroll
event of the VScrollBar
:
private void vScrollBar1_Scroll(object sender, ScrollEventArgs e)
{
GridViewInfo viewInfo = gridView1.GetViewInfo() as GridViewInfo;
if (viewInfo != null)
{
gridView1.TopRowIndex = (int)(
(gridView1.RowCount - viewInfo.RowsInfo.Count)
*
(1 + (1.0 * vScrollBar1.LargeChange / vScrollBar1.Maximum))
*
vScrollBar1.Value / vScrollBar1.Maximum
);
}
}
Where:
viewInfo.RowsInfo.Count
= visible rows countgridView1.RowCount - viewInfo.RowsInfo.Count
= maximum index that can be set to be the top.
vScrollBar1.Value / vScrollBar1.Maximum
= percentage scrolled of the scrollbar.
vScrollBar1.Maximum = gridView1.RowCount - gridView1.RowCount / 17;
private void vScrollBar1_ValueChanged(object sender, EventArgs e)
{
gridView1.TopRowIndex = vScrollBar1.Value;
}
private void gridView1_TopRowChanged(object sender, EventArgs e)
{
vScrollBar1.Value = gridView1.TopRowIndex;
}
gridView.MouseWheel += new MouseEventHandler(gridView1_TopRowChanged);
精彩评论