R
Rob Oldfield
Hi,
I want to conditionally format a column in a datagridview according to the
value in a different of my datasource. So if col 1 is true, then display col
2 in a different colour.
I know that I can use the cell formatting event if I want to conditionally
format the cell according to the value in that same column but is that the
best method to use if I'm using a different column for the condition?
Is this the best way of doing it, or is there something better?
In cell formatting event...
if dg.columns(e.columnindex).datapropertyname="ConditionColumn" then
if e.value=conditionvalue then
dim cell as datagridviewcell=dg(hard-coded column number,
e.rowindex)
cell.style.... do whatever formatting required
end if
end if
Would be a bit of a kludge having to hard code the 'target' column number
but I would actually replace that with a find on the datacolumns of the grid.
In my case, I don't actually need the column that is being looked at for the
condition on the grid. Does it HAVE to be there? Problem there is that if I
add it and make it invisible then the formatting event doesn't kick in.
I want to conditionally format a column in a datagridview according to the
value in a different of my datasource. So if col 1 is true, then display col
2 in a different colour.
I know that I can use the cell formatting event if I want to conditionally
format the cell according to the value in that same column but is that the
best method to use if I'm using a different column for the condition?
Is this the best way of doing it, or is there something better?
In cell formatting event...
if dg.columns(e.columnindex).datapropertyname="ConditionColumn" then
if e.value=conditionvalue then
dim cell as datagridviewcell=dg(hard-coded column number,
e.rowindex)
cell.style.... do whatever formatting required
end if
end if
Would be a bit of a kludge having to hard code the 'target' column number
but I would actually replace that with a find on the datacolumns of the grid.
In my case, I don't actually need the column that is being looked at for the
condition on the grid. Does it HAVE to be there? Problem there is that if I
add it and make it invisible then the formatting event doesn't kick in.