locked
Unable to cancel datagridview RowDefaultCellStyle RRS feed

  • Question

  • I have a datagridview in a project.At some earlier stage I may have set its RowDefaultCellStyle.Backcolor property or some other property.

    The problem is that now I want to change the backcolor of certain columns using the Datagridview1.Columns(2).DefaultCellStyle.Backcolor = color.green.

    However,it seems because I have earlier set the row properties,those properties are now overriding the cell properties.

    Is there a way to prevent this or to restore the default properties of the row?

    I have already tried to restore the original values of the row property but cannot stop the overriding.

    In the same project,I have another DGV where I am able to easily change the cell backcolor.In this DGV,I have never changed the row properties.

    Thank You,

    Khalid.

    Thursday, September 7, 2017 3:57 PM

Answers

  • Of course the thing here to do is find out where you made the change, if not in code then in the form designer which you can inspect via under project menu, "Show all files" then you can open the designer and inspect the DataGridView properties that may have been set in the property window for the DataGridView. You can find the change, close the designer then make the change as you normally would in the property window for the DataGridView. If the change was not done via the designer then you must search through your code looking for changes as there is no magical way to remedy this.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by Khalid Kagzi Friday, September 8, 2017 8:43 AM
    Thursday, September 7, 2017 4:53 PM

All replies

  • Of course the thing here to do is find out where you made the change, if not in code then in the form designer which you can inspect via under project menu, "Show all files" then you can open the designer and inspect the DataGridView properties that may have been set in the property window for the DataGridView. You can find the change, close the designer then make the change as you normally would in the property window for the DataGridView. If the change was not done via the designer then you must search through your code looking for changes as there is no magical way to remedy this.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by Khalid Kagzi Friday, September 8, 2017 8:43 AM
    Thursday, September 7, 2017 4:53 PM
  • Hi Khalid,

    From DataGridView.RowsDefaultCellStyle Property , we can know that The DataGridView control displays its cells using the styles indicated by the cell InheritedStyle property, which inherits styles from other properties of type DataGridViewCellStyle. For cells in all rows, excluding header cells, the styles specified through the RowsDefaultCellStyle property override the styles specified through the DefaultCellStyle and DataGridViewColumn.DefaultCellStyle properties, and are overridden by the styles specified through the AlternatingRowsDefaultCellStyle, DataGridViewRow.DefaultCellStyle, and DataGridViewCell.Style properties.  

    So if you use RowDefaultCellStyle.Backcolor property, we could not cancel this style.

    Best Regards,

    Cherry  

                    


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, September 8, 2017 4:32 AM
  • Of course the thing here to do is find out where you made the change, if not in code then in the form designer which you can inspect via under project menu, "Show all files" then you can open the designer and inspect the DataGridView properties that may have been set in the property window for the DataGridView. You can find the change, close the designer then make the change as you normally would in the property window for the DataGridView. If the change was not done via the designer then you must search through your code looking for changes as there is no magical way to remedy this.

    Ok,I found one line of code in the Designer(related to the DGVRowDefaults) and commenting out that line solved the issue.Thanks.

    BTW,I had not really asked for any magical way but only a suggestion on how to solve it.Thanks anyway.

    Khalid.

    Friday, September 8, 2017 8:43 AM