Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

DataGridViewRow Default Cell Style Applying to All Rows

Posted on 2009-05-20
3
1,250 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Open a link in vb.net 2 15
Why do I get the message "Message has been thrown by target of an invocation"? 22 46
Vb.net threads keep increasing 2 34
SSRS Deployment problem 5 63
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…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

766 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