Link to home
Start Free TrialLog in
Avatar of riceman0
riceman0

asked on

Can I disable a button in a DataGridViewButtonCell?

Can I disable a button embedded in a DataGridView, created by adding a DataGridViewButtonColumn?

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of elimesika
elimesika
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of riceman0
riceman0

ASKER


Oh my gosh.  In other words, no.  

But you've heroically added the functionality that was missing.  Standing ovation.

I'll need to think about whether I want to add that much code to my app for such a simple thing, but that is good work.
This is straight from the MSDN site. The problem is that it doesn't work when there are more rows in the grid than can be displayed on the form. The example code only deals with 8 rows. When you try to scroll down, it generates an error.

System.ArgumentOutOfRangeException was unhandled by user code
  Message="Specified argument was out of the range of valid values.\r\nParameter name: rowIndex"
  Source="System.Windows.Forms"
  ParamName="rowIndex"
  StackTrace:
       at System.Windows.Forms.DataGridViewCell.GetInheritedStyle(DataGridViewCellStyle inheritedCellStyle, Int32 rowIndex, Boolean includeColors)
       at System.Windows.Forms.DataGridViewCell.get_FormattedValue()
       at Guggenheim.UI.Grid.DataGridViewDisableButtonCell.Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, Int32 rowIndex, DataGridViewElementStates elementState, Object value, Object formattedValue, String errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) in C:\Documents and Settings\sddamge\My Documents\Visual Studio 2008\Projects\Class Libraries\GridSolution\Guggenheim.UI.Grid\DataGridViewDisableButtonCell.vb:line 81
       at System.Windows.Forms.DataGridViewCell.PaintWork(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, Int32 rowIndex, DataGridViewElementStates cellState, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
       at System.Windows.Forms.DataGridViewRow.PaintCells(Graphics graphics, Rectangle clipBounds, Rectangle rowBounds, Int32 rowIndex, DataGridViewElementStates rowState, Boolean isFirstDisplayedRow, Boolean isLastVisibleRow, DataGridViewPaintParts paintParts)
       at System.Windows.Forms.DataGridViewRow.Paint(Graphics graphics, Rectangle clipBounds, Rectangle rowBounds, Int32 rowIndex, DataGridViewElementStates rowState, Boolean isFirstDisplayedRow, Boolean isLastVisibleRow)
       at System.Windows.Forms.DataGridView.PaintRows(Graphics g, Rectangle boundingRect, Rectangle clipRect, Boolean singleHorizontalBorderAdded)
       at System.Windows.Forms.DataGridView.PaintGrid(Graphics g, Rectangle gridBounds, Rectangle clipRect, Boolean singleVerticalBorderAdded, Boolean singleHorizontalBorderAdded)
       at System.Windows.Forms.DataGridView.OnPaint(PaintEventArgs e)
  InnerException: