Solved

DataGridViewRow Default Cell Style Applying to All Rows

Posted on 2009-05-20
3
1,249 Views
Last Modified: 2012-05-07
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()

        Debug.WriteLine("MarkDummy")

        Dim dgvr As DataGridViewRow = GetDataGridRowFromDataRow(DataGridView_DataTable, _dummyRow)

        If Not dgvr Is Nothing AndAlso Not dgvr.HasDefaultCellStyle Then
            dgvr.DefaultCellStyle = _dummyRowStyle
        End If

    End Sub

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.


0
Comment
Question by:jedwar26
  • 2
3 Comments
 
LVL 15

Accepted Solution

by:
JackOfPH earned 500 total points
ID: 24438511
Where did you call the sub routine MarkDummyRow?

0
 

Author Comment

by:jedwar26
ID: 24438797
It was getting called from inside a few different event handlers -- and it appears setting this style inside the event handlers was the root of the problem.

I moved the call to markDummyRow to a few other places -- it needs to be called after any change (change to data source, change to sorting, etc.)  and I no longer have the issue.



0
 

Author Closing Comment

by:jedwar26
ID: 31583617
The expert's comment was helpful in resolving the issue but wasn't the final solution.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question