1

I would like to have two buttons dynamically added to a column of cells in my DataGridView. The column in question says "Amount". And the buttons I would like should increase/decrease the value in that cell. Maybe with an up/down-arrow, or +/- sign. I made a poor image to try and explain what I'm looking for:

enter image description here

I need these buttons to be added for each row in the DataGrid

Is it possible to do this, or do I need to look for another solution?

2
  • Wpf or winforms? Commented Mar 10, 2017 at 10:50
  • Winforms. (Comments must be at least 15 characters in length) Commented Mar 10, 2017 at 11:32

2 Answers 2

1

I suggest you use NumericUpDown instead of button, there is an exemple to achieve this :

Build a Custom NumericUpDown Cell and Column for the DataGridView Control

NumericUpDown cell for DataGridView

Sign up to request clarification or add additional context in comments.

2 Comments

What if link will become unavailable next month? Link-only answers are not reliable and low quality answers. Consider to provide relevant code and/or details from linked resources. And provide links for further reading
I tried using the sample provided in the link you sent me. Sadly it seems outdated. This would be fine, because it works, if it wasn't for one bug that I can't live with. (If I have two rows, and click 'up arrow' in the first row, until it reaches '3'. Then click 'up arrow' in the second row, it will start from '3' and go up to '4' immediately.) Is there a more recent version of this somewhere? (I didn't understand the tutorial well enough to make my own version.)
0

You need to create a custom cell. There's an example from MS for a custom cell which holds a DateTimePicker Control. That could be taken as a start point for your custom control.

DateTimePicker example (Windows Forms)

https://msdn.microsoft.com/en-us/library/7tas5c80.aspx

Here's the MS reference for Windows Forms

https://msdn.microsoft.com/en-us/library/ms171618(en-us,vs.80).aspx

I've never used WPF but I would expect that the DatGridView-Class is the same in WindowsForms and WPF.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.