How to detect the vertical scrollbar in a DataGridView control

后端 未结 7 750
半阙折子戏
半阙折子戏 2021-01-05 05:19

Using winforms in vs2008. I have a DataGridView and I would like to detect when the vertical scroll bar is visible. What event should I register for?

I am adding the

7条回答
  •  庸人自扰
    2021-01-05 05:50

    I gave Hans Passant the Check mark since he answered the question asked... However, I went another route for the solution. Since the dialog box is modal, the list of items will not change from the time it is created. So I am able to call the code below to ensure that the textboxes are in the correct location when the dialog first displays.

      /// 
      /// Horizontally shifts the label and text boxes that display the total
      /// values so that the totals remain aligned with the columns.
      /// 
      private void ShiftTotalsDisplay(DataGridView grid, Label firstLabel,
         TextBox secondTextBox, TextBox thirdTextBox)
      {         
         //Note if you have a rowheader add the width here also.
         int nameRightLoc = grid.Location.X +            
            grid.Columns[0].Width;
         int fpRightLoc = nameRightLoc +
            grid.Columns[0].DividerWidth +
            grid.Columns[1].Width;
         int dlRightLoc = fpRightLoc + 
            grid.Columns[1].DividerWidth +
            grid.Columns[2].Width;
    
         Point loc = firstLabel.Location;
         loc.X = nameRightLoc - firstLabel.Width - 2;
         firstLabel.Location = loc;
    
         loc = secondTextBox.Location;
         loc.X = fpRightLoc - secondTextBox.Width - 2;
         secondTextBox.Location = loc;
    
         loc = thirdTextBox.Location;
         loc.X = dlRightLoc - thirdTextBox.Width - 2;
         thirdTextBox.Location = loc;         
      }
    

提交回复
热议问题