Ask your PowerShell-related questions, including questions on cmdlet development!
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 4 years and 11 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.
This time I'm trying to add a button column to a DataGridView control, but I only want the button in each row to be enabled if certain parameters are met. What I'm having trouble with is designating the button I'm trying to disable/enable. I don't really have a code example because I'm pretty sure I'm doing it wrong anyways...
What I do know I'm doing right (with my variables substituted out, of course):
This populates all my computer names properly, along with the version and update date of each. The 4th column is the button column I'm referring to. The designer automatically adds a button for each row, which is great. I want to disable the ones that don't meet a certain criteria.
Any suggestions from anyone with this weak description? Any help is appreciated. If you have any other questions I'll do my best to answer.
You will have to manage the buttons programmatically but, unfortunately, this cannot be done with PowerShell. You will have to write C# code to alter the buttons behavior as the control in the cell is not exposed to the PS environment.
The important thing to note is that the "CellButton" has no events and is not a true button. It has no "enabled" or "visible" properties. It exisits as a pure slave of the grid control and just displays text. The grid handles the CellClick event. You can, possibly, use the cell click to ignore the click for specific buttons. You can also use the "CellPaint" to alter the color of the button.
Hmmm, that's unfortunate... That's kind of the same conclusion I was beginning to draw through the research I've done so far.
Would my best solution be possibly to build a boolean array that controls whether a button is "enabled" or not, and check in the DataGridView's cellclick event to make sure it's the cell in the last column that's clicked, and that it matches one of the "enabled" indexes in my array? That's the main idea coming to mind.
I want the button to kill a process when clicked on the PC listed in that row, but I only want the button to display (or at least only be clickable) if that PC has the program I'm killing already running.
This topic is 4 years and 11 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.