I have a DataGridView in my C # application. Using the constructor, I set AlternatingRowsDefaultCellStyle , as well as the DefaultCellStyle properties on the DGV itself. Both of these styles have pad values โโof 0, 0, 5, 0 . I did not set any custom styles for any of the DGV columns from the Edit Columns menu in the DataGridView task add-in.
There is one image column in DGV in which I draw a small graph for each row. I would like to remove the registration from all the cells in this column, so that no padding is added to the cell, which leaves some spaces at the end of the graph.
Each of the following things I tried does not remove the registration from any cells in the column, but also does not throw any exceptions.
// first attempt // taken from http://social.msdn.microsoft.com/Forums/eu/winforms/thread/a9227253-8bb4-429a-a700-8a3a255afe4d deviceGrid.Columns["GProduction"].DefaultCellStyle.Padding = new Padding(0); // second attempt DataGridViewCellStyle style = deviceGrid.Columns["Graph"].DefaultCellStyle; // also tried Clone() style.Padding = new Padding(0); deviceGrid.Columns["GProduction"].DefaultCellStyle = style; // third attempt DataGridViewColumn col = deviceGrid.Columns["Graph"]; DataGridViewImageCell icell = new DataGridViewImageCell(); icell.Style.Padding = new Padding(0); col.CellTemplate = icell;
I suspect that perhaps the DefaultCellStyle addition from the DataGridView itself overrides the default cell style that I am trying to set for the column, but if so, what should I do to prevent this?
DECISION:
After executing the provided jmh_gr, I found that the problem is that the DefaultCellStyle for the DataGridView itself is inherited by LAST on the cell, so I had to remove the padding from the DGV properties and apply it to all columns except those that I did not want to fill.
drew010
source share