I have a DataGridView that is bound to a bindingsource that has a DataView as its datasource. The DataGridView shows data read from a MSSQL 2005 database, plus one other row I call the dummy row that is added to the datatable dynamically. This is a row where the user can select and enter data to create a new row of data in the database table.
The dummy row is formatted differently from the other rows to make it stand out, with a yellow backcolor and italicized font.
I have an object, _dummyRowStyle of type DataGridViewCellStyle, that is assigned to the default cell style of the dummy row, like this:
Private Sub markDummyRow()
Dim dgvr As DataGridViewRow = GetDataGridRowFromDataRow(DataGridView_DataTable, _dummyRow)
If Not dgvr Is Nothing AndAlso Not dgvr.HasDefaultCellStyle Then
dgvr.DefaultCellStyle = _dummyRowStyle
From tracing the code and looking at debug output, I know this sub only gets called once and only sets the defaultcellstyle for one row.
The problem is that the entire DataGridView gets set with this style instead of just one row. If I then sort the DataGridView by clicking on a columnheader, the DataGridView then displays the formatting I want:only the dummy row is formatted differently and everything looks fine.
Any ideas why when I set the style for one DataGridViewRow, it is affecting the entire DataGridView? Am I missing something with style inheritance?
If I can't get this to work, I plan on redoing the logic to use cell paint events to handle my special formatting needs instead of using cell styles.