Adding buttons to DataGridView Column cells

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 7 years and 2 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
IanUoY
Posts: 91
Last visit: Wed Sep 20, 2023 2:44 am

Adding buttons to DataGridView Column cells

Post by IanUoY »

Product, version and build: Powershell Studio 2016 5.3.131
32 or 64 bit version of product:64
Operating system:W7
32 or 64 bit OS:64
PowerShell Version:4

In a nutshell, I would like to insert buttons into the cells of a particular column to give the end user an easy way of editing/deleting the row in question by clicking the appropriate button (the population of the datagridview only contains a subselection of the information that may need to be edited).

Regards

Ian
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Adding buttons to DataGridView Column cells

Post by davidc »

[TOPIC MOVED TO THE POWERSHELL GUIS FORUM]
David
SAPIEN Technologies, Inc.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Adding buttons to DataGridView Column cells

Post by jvierra »

Just set the column type to command button. Select DataGridViewButton in the designer.
User avatar
IanUoY
Posts: 91
Last visit: Wed Sep 20, 2023 2:44 am

Re: Adding buttons to DataGridView Column cells

Post by IanUoY »

Fingers crossed.....third time I've posted this reply!

I'd spotted the datagrdiviewbuttoncolumn, which I've added, and works ok for what it is.

Ideally I would have liked to put a few buttons, but I can easily add a few datagridviewbuttoncolumns.

What I would now like to do is add an icon to the button rather than just plain text, certainly the aesthetics are much better....played around with datagridviewimagecolumn, but the button column ensures it acts like a button when clicking.

Could you advise how I could do this?

Thanks

Ian
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Adding buttons to DataGridView Column cells

Post by jvierra »

You can't. In this situation we would use a context menu. You can also use a checkbox and arrange pretty buttons next to the grid that operate on selected rows.
User avatar
IanUoY
Posts: 91
Last visit: Wed Sep 20, 2023 2:44 am

Re: Adding buttons to DataGridView Column cells

Post by IanUoY »

Thanks for the quick response, what do you mean by Context Menu?

Previously I've had a textbox somewhere which shows selected user for example, with option buttons, I just wanted to make it a bit neater.

Presumably quite a bit of extra work to put separate icons outside the gridview as would have to create these on the fly presumably depending on how many rows are returned to the gridview, if less rows than the full view.

I'm just wondering whether to stick with the imagecolumn....nothing quite ideal unfortunately.

Ian
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Adding buttons to DataGridView Column cells

Post by jvierra »

I recommend reading the blog posts here on using forms. You seem to be missing most or teh design fundamentals.

There is a post on context menus here: http://info.sapien.com/index.php/guis/gui-scripting

You will find many articles on ways to sex up a form including fade-outs and animations. Once you have an understanding of forms you will see many ways to get your project done painlessly.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Adding buttons to DataGridView Column cells

Post by jvierra »

User avatar
IanUoY
Posts: 91
Last visit: Wed Sep 20, 2023 2:44 am

Re: Adding buttons to DataGridView Column cells

Post by IanUoY »

Yep I get what you mean now. Unfortunately I get very little chance to do anything like this, and so almost have to start from scratch each time.

Another option I'm looking at is to use the datagridviewimagecolumn and when a cell is that column is clicked change the background color or similar, then at least there's a response to the click.

Cheers

Ian
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Adding buttons to DataGridView Column cells

Post by jvierra »

IanUoY wrote:Yep I get what you mean now. Unfortunately I get very little chance to do anything like this, and so almost have to start from scratch each time.

Another option I'm looking at is to use the datagridviewimagecolumn and when a cell is that column is clicked change the background color or similar, then at least there's a response to the click.

Cheers

Ian
Just catch the cell click and do what you need. Now is the time to take to learn how to work with forms. Once you read the articles you will have enough information to build without forgetting.
This topic is 7 years and 2 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked