I have a desktop application made in VisualStudio in C#.
This table shows the names of several files uploaded to a server, and a column with a Check to select which ones you want to download.
When the app is opened, all cells are unchecked and the Download button is disabled.
I want when a checkbox is clicked to change the button property based on whether there is any checkbox selected. If there is not, it will be disabled again.
I have tried with event CellClick
, CellContentClick
, CellValueChanged
... many. But when I put the code 1 , and I click on the checkbox, until I click on another cell the code is not executed.
What event should I use so that as soon as I click, without having to click outside or in another cell, it calculates the state in which the button has to be?
1 Code:
bool guardar = false;
foreach (DataGridViewRow row in gvDocumentos.Rows)
{
if (Convert.ToBoolean(row.Cells[2].Value) == true)
{
guardar = true;
}
}
btnDescargar.enabled = guardar;
do a test like this
In the constructor add the handlers for the CellContentClick and CellValueChanged events
It then handles the events as follows:
Try as follows:
And add this code to it to let it know
DataGridView
that you're done making changes to itCheckBox
:Reference
Testing with my example (which you brought me from my query) hahaha I'm testing while I wait if you can help me with my question and it works on the first click when you use the event:
Try it and then you tell me... it's wonderful!!! hahahaha and without any additional code