我有一个具有DevExpress GridView的表单。 GridView有近100列。目前,我一次向用户显示30列,其余列可以通过右侧滚动来访问。
我希望实现一个功能,使我在文本框中输入一个值(列号)并单击一个按钮(例如),而不是滚动,它应该导航到gridView中的特定列。
到目前为止,我能够实现以下内容:
如果假设,在开头我显示第1-30列并搜索第45列,它会显示在最右边选择列的结果。
如果假设,在开头我向用户和搜索栏10显示了20-50列,它显示在最右边。
我希望以这样的方式实现:每当我搜索一列时,它不应该显示在最右边或左边,而应该显示在中心。
请检查下面给出的代码。逻辑似乎很好,但它无法正常工作。
private void SetLeftCoord(int toBeFocusedIndex)
{
int currLeftEndColIndex = gvVisualizeNextGenSequence.LeftCoord / gvVisualizeNextGenSequence.VisibleColumns[0].Width;
int currRightEndColIndex = currLeftEndColIndex - 1 + GetVisibleColumnCount(gvVisualizeNextGenSequence);
if (toBeFocusedIndex < currRightEndColIndex && toBeFocusedIndex > currLeftEndColIndex)
{
int difference = toBeFocusedIndex - currLeftEndColIndex;
gvVisualizeNextGenSequence.LeftCoord +=
(difference * gvVisualizeNextGenSequence.VisibleColumns[0].Width) -
(GetVisibleColumnCount(gvVisualizeNextGenSequence) / 2) * gvVisualizeNextGenSequence.VisibleColumns[0].Width;
}
if (toBeFocusedIndex < (GetVisibleColumnCount(gvVisualizeNextGenSequence) / 2) ||
toBeFocusedIndex > gvVisualizeNextGenSequence.VisibleColumns.Count - (GetVisibleColumnCount(gvVisualizeNextGenSequence) / 2))
{ }
if (toBeFocusedIndex < currLeftEndColIndex)
{ gvVisualizeNextGenSequence.LeftCoord -= (GetVisibleColumnCount(gvVisualizeNextGenSequence) / 2) * gvVisualizeNextGenSequence.VisibleColumns[0].Width; }
if (toBeFocusedIndex > currRightEndColIndex)
{ gvVisualizeNextGenSequence.LeftCoord += (GetVisibleColumnCount(gvVisualizeNextGenSequence) / 2) * gvVisualizeNextGenSequence.VisibleColumns[0].Width; }
gvVisualizeNextGenSequence.FocusedColumn = gvVisualizeNextGenSequence.Columns["Column" + toBeFocusedIndex];
}
还有其他办法吗? “在任何时候,我的专栏应该在网格的中心”
谢谢
Mangesh Vilas Kaslikar
答案 0 :(得分:1)
gridview1.LeftCoord = (gridview1.FocusedColumn.VisibleIndex - visibleColumnsCount / 2) * gridview1.VisibleColumns[0].Width;
Visiblecolumnscount = // count of currently visible columns in the view
public int GetVisibleColumnCount(GridView view)
{
GridViewInfo info = view.GetViewInfo() as GridViewInfo;
int visibleColumnCount = 0;
for (int i = 0; i < view.VisibleColumns.Count; i++)
{
if (info.GetColumnLeftCoord(view.GetVisibleColumn(i))
< view.ViewRect.Width - info.ViewRects.IndicatorWidth)
visibleColumnCount++;
}
return visibleColumnCount;
}