Is it possible to change the color of a single cell while adding it, resp. directly after it?
like this:
$CurrentRow = $datagridview1.Rows.Add($Computer.ID, $Computer.OSDComputerName, $Computer.ComputerName, $Computer.MacAddress, $Computer.UUID, $UDAUser, $Computer.UILanguage, $Computer.UserLocale, $Computer.KeyboardLocale, $Computer.Description, $Computer.ModifiedBy, $Computer.Modified)
if ($Computer.Macaddress)
{
$datagridview1.Rows[$CurrentRow].Cells["MacAddress"].Style.BackColor = "Red"
}
Because I get this:
The property 'BackColor' cannot be found on this object. Verify that the property exists and can be set
regards, Roland
Change color of single cell while adding rows
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.
Re: Change color of single cell while adding rows
Change cell colors in the "paint" event where you can check the value of the cell and set the color.
Cells can always be accessed by just specifying the cell name in the row:
Row.Cells['mycell'].Style.Backcolor = 'Red'
If this doesn't work then your columns may have a different name or have not been named.
Cells can always be accessed by just specifying the cell name in the row:
Row.Cells['mycell'].Style.Backcolor = 'Red'
If this doesn't work then your columns may have a different name or have not been named.
Re: Change color of single cell while adding rows
that was actually the issue, missing name for the column.
I've added an additional one, but I can't find it anymore where I do the naming of the column in the GUI
I've done it in code until I know again where to do it in the GUI...
2nd.
My original code works now, but can I refer simpler to the just created row instead of doing this:
$CurrentRow = $datagridview1.Rows.Add($Computer.ID, $Computer.OSDComputerName, $Computer.ComputerName, $Computer.MacAddress, $Computer.UUID, $UDAUser, $Computer.UILanguage, $Computer.UserLocale, $Computer.KeyboardLocale, $Computer.Description, $Computer.ModifiedBy, $Computer.Modified)
$datagridview1.Rows[$CurrentRow].Cells["UUID"].Style.BackColor = 'LightGray'
I've added an additional one, but I can't find it anymore where I do the naming of the column in the GUI
I've done it in code until I know again where to do it in the GUI...
2nd.
My original code works now, but can I refer simpler to the just created row instead of doing this:
$CurrentRow = $datagridview1.Rows.Add($Computer.ID, $Computer.OSDComputerName, $Computer.ComputerName, $Computer.MacAddress, $Computer.UUID, $UDAUser, $Computer.UILanguage, $Computer.UserLocale, $Computer.KeyboardLocale, $Computer.Description, $Computer.ModifiedBy, $Computer.Modified)
$datagridview1.Rows[$CurrentRow].Cells["UUID"].Style.BackColor = 'LightGray'
Re: Change color of single cell while adding rows
No. The index is returned just for this and other reasons.
If you autogenerate the grid using a proper datasource or a datatable then the names will be assigned automatically.
The name property is part of the column object in the designer. You assign the name when creating a new column.
If you autogenerate the grid using a proper datasource or a datatable then the names will be assigned automatically.
The name property is part of the column object in the designer. You assign the name when creating a new column.