Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

DataGridViewRow Default Cell Style Applying to All Rows

Posted on 2009-05-20
3
Medium Priority
?
1,261 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
[X]
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
  • 2
3 Comments
 
LVL 15

Accepted Solution

by:
JackOfPH earned 1500 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 Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

721 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