views:

286

answers:

2

I've created another header row for a gridview programmatically. In this row I have a few controls including a label that I want to align all the way to the left of the cell. The one cell has a columnspan of 7 so it runs across the entire gridview. how do i align that label programmatically??

  Dim cell As New TableCell
  Dim lblfilter As New Label
  Dim row As New GridViewRow(-1, -1, DataControlRowType.Header, DataControlRowState.Normal)
    GridView1.Rows(0).Parent.Controls.AddAt(0, row)

lblfilter.ForeColor = Drawing.Color.AntiqueWhite    
cell.Controls.Add(lblfilter)
A: 

If you set Docking to Left in code you should be able to achieve that.

in C#:

lblfilter.Dock = DockStyle.Left;

That should dock it to the left of whatever container it is in.

Kurisu
Didn't work. It doesn't have a dock attribute. Thanks though.
Eric
Are you sure? The System.Windows.Forms.Label Control does have a Dock attribute (just checked myself). Are you using something different?
Kurisu
Yeah, for whatever reason it doesn't have that attribute. I even tried importing system.windows.forms.label
Eric
It should. Try to change your line to: Dim lblfilter As New Windows.Forms.Label
Meta-Knight
Ok. I get the attribute but I can't Add the label to the Grid's new row. Value of type 'System.Windows.Forms.Label' cannot be converted to 'System.Web.UI.Control'.here's how i add it:cell.Controls.Add(lblfilter)
Eric
A: 

hi, you can try setting a css style to the label. Here is an example:

.leftLabel
{
float: left;
}

and then you set the style to the label like this:

lblfilter.CssClass = "leftLabel"
Teddy