English 中文(简体)
DataGridView: how to make scrollbar in sync with current cell selected?
原标题:DataGridView: how to make scrollbar in sync with current cell selection?

我有一个窗口申请,数据GridView作为数据列报。 每2分钟将用新的数据更新电网。 为了与新增加的数据保持一致,我不得不重新制定设想方案:

dbv.Rows.Clear(); // clear rows
SCrollBars sc = dbv.ScrollBars;
dbv.ScrollBars = ScrollBars.None;
// continue to populate rows such as dbv.Rows.Add(obj);
dbv.ScrollBars = sc; // restore the scroll bar setting back

根据上述代码,在数据更新后,滚动酒吧重新开脱。 问题是,申请要求按照复读后选择的单元:

dbv.CurrentCell = dbv[0, selectedRowIndex];

根据上述代码,选定了牢房;但是,滚动酒吧的位置并不反映选定牢房的浏览位置。 当我试图在复习后搬进餐厅时,电网将升入第一行。

看来,在重新启动后,滚动酒吧的位置被重新定位为0。 设置电网海流体的代码并不导致电梯条形重新定位到正确位置。 如我所知,在数据GriadView中,没有任何财产或方法获得或设定保值。

我也试图把选定的行文放在顶上:

dbv.CurrentCell = dbv[0, selectedRowIndex];
dbv.FirstDisplayedScrollingRowIndex = selectedRowIndex;

该行将排在顶端,但滚动酒吧仍然处于 out状态。 无法确定是否有办法使雕像与法典中确定的选定行合起来?

最佳回答

我找到了解决问题的答案。 正如我提到,控制没有办法或财产来确定正确的滚动交易价值。 然而,如果直接与统一管理公司(例如连接滚动酒吧或电网)进行互动,则电线和电网内容将显示正确。 它认为,控制需要重新调整重点,重新开始。

简言之,使用以下代码并不造成滚动条 bar:

 dgv.Select();
 // or dbv.Focuse();

我发现的方式是,我不得不使数据电网控制再次消失。 幸运的是,我用几张表格进行制表控制。 接着,我转开了表格,以便重新打开滚动酒吧:

int index = myTabCtrl.SelectedIndex;
if (index == (myTabCtrl.TabCount)) {
  dgv.SeletecedIndex = 0;
}
else {
  dgv.SelectedIndex = index + 1;
}
myTabCtrl.SelectedIndex = index;

如果你没有办法隐藏你表格上的数据格文,那么你就可以简单地把表格减少到最低限度,然后恢复。

问题在于,国际律师联合会将出现新的情况。

问题回答

It seems, TAB, SHIFT+TAB, END keys don t always bring last column into the visible view. The following code inside the CurrentCellChanged event handler seems to fix this issue (vb.net):

If Me.MyDataGridView.CurrentCell IsNot Nothing Then
    Dim currentColumnIndex As Integer = e.MyDataGridView.CurrentCell.ColumnIndex
    Dim entireRect As Rectangle = _ 
           Me.MyDataGridView.GetColumnDisplayRectangle(currentColumnIndex, False)
    Dim visiblePart As Rectangle = _
           Me.MyDataGridView.GetColumnDisplayRectangle(currentColumnIndex, True)

    If (visiblePart.Width < entireRect.Width) Or (entireRect.Width = 0) Then
        Me.MyDataGridView.FirstDisplayedCell = Me.MyDataGridView.CurrentCell
         OR Me.MyDataGridView.FirstDisplayedScrollingColumnIndex = currentColumnIndex
    End If
End If




相关问题
Visual studio tag highlighting feature is missing!

I need a little assistance with regards to my visual studio IDE. There is this feature in aspx markup pages to highlight the matching tags when you click on them. <td ...

How to split a Crystal Reports subreport across a page break?

I m using Visual Studio 2005 and writing in VB.NET. I have a subreport in a Crystal Reports report consisting of a list of log entries. Sometimes the list of log entries is long enough that it would ...

Reset Function in Visual C#

Finally I made a game using Visual C# ... (With Help Of Stackoverflow members ,,, Thanx). I Have three more questions. 1- How can I add a reset function to the application form I mean I want it to ...

VS 2005 Setup - HKCU

I am trying to fix an existing application that uses a Visual Studio 2005 setup project. We are requiring it to work on limited user accounts for XP, our app is written in C# for .Net 2.0. It writes ...

SOAP and WSDL in webservice

I am a beginner to webservice concepts. Now I know how to deploy webservice in IIS. I checked the webservice URL There I can see SOAP protocol contents and WSDL (after url type ?WSDL). My questions ...

Unable to generate PDB files in Visual Studio 2005

For most assemblies, I m able to generate their respective .pdb files. However, I ve got one project that isn t generating their .pdb files. I ve made sure that it on debug mode and that the project ...

热门标签