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.
.NET ProgrammingVisual Basic.NET

Avatar of undefined
Last Comment
drewj840

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
elimesika

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
riceman0


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.
drewj840

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:
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy