datagrid cellstyle alignment
Hello,
I am trying to change the datagrid cellstyle alignment of a column in the designer. I set it to middle right but then I run it and it still aligned to the left. I have a lot of datagrids in my application but there are few that doesn't accept any alignment settings which I don't understand at all, can't see any reason, I been looking through the options if there is anything but can't find anything.
I just need one column of cells to be aligned to the right
whatever I do all of the columns are aligned left and there is an option in the defaultcellstyle that is sat to middle left, but when I try to change it to Not Set it doesn't change.
Any advice?
Thanks
Re: datagrid cellstyle alignment
does it work if you change it at runtime? and are these bound Datagrids?
Re: datagrid cellstyle alignment
well I can't change it at run time. I am not sure what means bound datagrid, but these are normal datagrids that a fill with data from the database, that's all.
Re: datagrid cellstyle alignment
Here's how I do it:
vb Code:
' Set Align-MiddleRight object
Dim objAlignMiddleRightCellStyle As New DataGridViewCellStyle()
objAlignMiddleRightCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
Then apply this object to the DataGridView cell:
vb Code:
Me.DataGridView1.Columns(2).DefaultCellStyle = objAlignMiddleRightCellStyle
Re: datagrid cellstyle alignment
Just noticed you asked how to do it in the designer. Not in code, as I provided.
If your dgv is bound to a Database, through a DataAdapter, DataTable, etc., Then I don't know how to changed the cell styles... except for doing so via code.
If you've added your Columns through the Designer you can adjust those properties if you click on the little box that comes up when you select the "Columns" property in the Property tool bar. Select the column in question and adjust its DefaultCellStyle property.
Re: datagrid cellstyle alignment
I have a feeling there is some option or I need to correctly configure the cellstyles, because either in designer or in code nothing is changing. What I can do is copy another datagrid that works fine with those and use it but that won't tell me the cause and I can't see the difference between them that work fine and those that doesn't let me modify the cellstyle.
Thanks anyway
1 Attachment(s)
Re: datagrid cellstyle alignment
I made a sample application with one of my datagrids copied, if anybody can change the defaultcellstyle for one of the columns please tell me how you do it :), in code or in designer whichever.
Thanks