borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (DataGrid formatting expression)Next Topic (HELP!!! PLEASE!!Estate Agenst system) New Topic New Poll Post Reply
AndreaVB Forum : VB.Net : datagrid column width
Poster Message
Anita
Level: Big Cheese

Registered: 19-05-2005
Posts: 24

icon datagrid column width

I am trying to figure out how to set the column width of a datagrid web control.  What event would I put the code in and what would the code look like?  

I've tried setting in the datagrid property builder, but it doesn't work.  

Can anyone help me?  Thank you.

22-02-2006 at 06:49 PM
View Profile Send Email to User Show All Posts | Quote Reply
Chris_871
Level: Master


Registered: 30-11-2002
Posts: 106
icon Re: datagrid column width

Hi

I am using DataGrid control in my windows application. I am changing the column width through DataGridTableStyle class.

Here is the sample function which I am using.

     Sub headgrid(ByVal str As String, ByVal dg As DataGrid)
        dg.Refresh()
        dg.TableStyles.Clear()
        Dim TS As New DataGridTableStyle()
        TS.MappingName = ds.Tables(str).ToString

        Dim colsrno As New DataGridTextBoxColumn()
        colsrno.HeaderText = "Sr.No"

        '    colsrno.ReadOnly = True
        colsrno.NullText = ""
        colsrno.MappingName = ds.Tables(str).Columns(0).ToString()
        colsrno.Width = 40

        Dim colDescription As New DataGridTextBoxColumn()
        colDescription.HeaderText = "Description"
        colDescription.NullText = ""
        colDescription.MappingName = ds.Tables(str).Columns(1).ToString()
        colDescription.Width = 150

        Dim colSolution As New DataGridTextBoxColumn
        colSolution.HeaderText = "Solution"
        colSolution.NullText = ""
        colSolution.MappingName = ds.Tables(str).Columns(2).ToString()
        colSolution.Width = 150

        Dim colDate As New DataGridTextBoxColumn
        colDate.HeaderText = "Date"
        colDate.NullText = ""
        colDate.MappingName = ds.Tables(str).Columns(3).ToString() 'here you can use the date format.
        colDate.Width = 150


        TS.GridColumnStyles.Add(colsrno)
        TS.GridColumnStyles.Add(colDescription)
        TS.GridColumnStyles.Add(colSolution)
        TS.GridColumnStyles.Add(colDate)
        dg.TableStyles.Add(TS)

    End Sub

In the above function str is a table.


I hope that it may help you.


Regards
Chris

24-02-2006 at 04:51 AM
View Profile Send Email to User Show All Posts | Quote Reply
Anita
Level: Big Cheese

Registered: 19-05-2005
Posts: 24
icon Re: datagrid column width

Thanks, I'm going to try this.  

27-02-2006 at 02:31 PM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : VB.Net : datagrid column width
Previous Topic (DataGrid formatting expression)Next Topic (HELP!!! PLEASE!!Estate Agenst system) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder