The datagrid has a tablestyle applied to it, and there
are DataGridTextBoxColumn and each DataGridTextBoxColumn
has an array of DataGridTextBox objects.
Private Sub highlight(ByVal str As String)
Dim myTextBoxcolumn As DataGridTextBoxColumn
Dim myTextBox As DataGridTextBox
'loop through the cells of the datagrid, searching
for the string
For c As Integer = 0 To
DataGrid1.VisibleColumnCount - 1
For r As Integer = 0 To
DataGrid1.VisibleRowCount - 1
'if the content of the sell matches the
str, we want to highlight it.
If CType(DataGrid1.Item(r, c), String) =
str Then
myTextBoxcolumn = _
CType(DataGrid1.TableStyles
(0).GridColumnStyles(c), DataGridTextBoxColumn)
myTextBox = CType
(myTextBoxcolumn.TextBox, DataGridTextBox)
myTextBox.BackColor = Color.Red
myTextBox.ForeColor = Color.Blue
End If
Next
Next
End Sub
This routine highlights the entire column, not just a
single cell, moreover, you can only see the highlighting
when the cell is selected (has the focus). Is there
anyway to have the cell highlighted, even when it is not
selected? It seems that the datagrid should be capable of
this, but I cannot find any objects which expose the
necessary properties...
I can highlight an entire row, or a column, but setting
the background color on a single cell, or multiple cells
on different rows and different columns still eludes me.
If any gurus would help, I would be very appreciative.
Kind Regards,
Greg
|