Validating cells in a column on a DataGridView
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.
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.
- falconcurt
- Posts: 19
- Last visit: Mon Jan 29, 2024 11:17 am
Validating cells in a column on a DataGridView
I am looking to validate each cell within the Password column on my DataGridView. I have created the DataGridViewCellValidatingEventHandler event on my form and I have my function to make sure the password meets the complexity requirements but not sure exactly how to put the cells in an array for that column and what to put in my Foreach ($cell in $column) {}. Any help to get me start would help.
- Attachments
-
- DataGrid.JPG (19.48 KiB) Viewed 2258 times
Re: Validating cells in a column on a DataGridView
The validate event execute for each column in the grid. YOu need to check the coloumn index to run your code only foro the password column. THe cell being validates is abtained from the RowIndex and COlumnIndex passed in the event.
Code: Select all
if($_.ColumnIndex -eq 3){
# this is the password column
# the following gets the cell being validated.
$cell = $datagridview1.Rows[$_.RowIndex].Cells[3]
}
- falconcurt
- Posts: 19
- Last visit: Mon Jan 29, 2024 11:17 am
Re: Validating cells in a column on a DataGridView
Ok, I guess this may not be the route i need. What i am trying to accomplish is importing a CSV file into the DataGridView window with all of the data. I would like it to highlight red if the Password doesn't meet the requirements. Is the DataGridViewCellValidatingEventHandler event the best route i need to take? It seems to only hightlight the cell after i click on the cell. I would like for it to populate without me clicking on it.
Re: Validating cells in a column on a DataGridView
To do that we would use the "Paint" event to set the color of the cell. Just set the backcolor based on the cells contents.
Example:
Example:
- Attachments
-
- Test-CellValidating2.psf
- (16.44 KiB) Downloaded 153 times
- falconcurt
- Posts: 19
- Last visit: Mon Jan 29, 2024 11:17 am