Resizing DataGrid columns...


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Resizing DataGrid columns...

  1. #1
    Russ Suter Guest

    Resizing DataGrid columns...


    I'm no slouch when it comes to VB programming but I can't seem to find out
    how to use code to resize columns in a datagrid control. I have my control
    bound to a typed dataset which creates 6 columns for the database info. What
    I really need to do is resize the columns in the DataGrid's resize event
    so that there is no wasted space at the end of the table. Can anyone help
    me figure out how to do this?

    Thanks,

    Russ...

    P.S. If anyone can also tell me where I need to intercept an event so that
    I can post an update AS SOON AS a cell is changed, I'd very much appreciate
    it.

  2. #2
    Stephen Muecke Guest

    Re: Resizing DataGrid columns...

    Russ,

    In the datagrids resize event, reference each column and set its new width

    Dim col As DataGridColumnStyle
    col =
    Me.DataGrid1.TableStyles("YourTableStyle").GridColumnStyles("YourColumnName"
    )
    col.Width = new value

    If you are filling the dataset programmatically, you will need to set a flag
    after creating the TableStyle because the Forms first resize event fires
    before the form is shown (ie the TableStyle will not exist), then put the
    above code in an If statement

    If bolFlag = True Then
    set column widths here
    End if

    It may be preferable to put this code in the DataGrids Layout event. This
    will prevent users from resizing the columns you have set.

    The only problem is that you need to take into account the possibility that
    the vertical scroll bar will be visible. Unfortunately, the datagrid
    ClientRectangle property also seems to include the scrollbars (unlike say
    the ListView control). This means you have to finish the last column about
    22 pixels from the RHS of the control. Hopefully someone else has the
    solution to this.

    Stephen Muecke

    "Russ Suter" <russ.suter@cox.net> wrote in message
    news:3cf69963$1@10.1.10.29...
    >
    > I'm no slouch when it comes to VB programming but I can't seem to find out
    > how to use code to resize columns in a datagrid control. I have my control
    > bound to a typed dataset which creates 6 columns for the database info.

    What
    > I really need to do is resize the columns in the DataGrid's resize event
    > so that there is no wasted space at the end of the table. Can anyone help
    > me figure out how to do this?
    >
    > Thanks,
    >
    > Russ...
    >
    > P.S. If anyone can also tell me where I need to intercept an event so that
    > I can post an update AS SOON AS a cell is changed, I'd very much

    appreciate
    > it.




  3. #3
    Stephen Muecke Guest

    Re: Resizing DataGrid columns...

    Russ,

    Further to my reply, have a look at the DataGrids section of the following
    site

    http://www.syncfusion.com/FAQ/WinForms/default.asp#44

    Stephen


    "Stephen Muecke" <stevejo@senet.com.au> wrote in message
    news:3d1d045b@10.1.10.29...
    > Russ,
    >
    > In the datagrids resize event, reference each column and set its new width
    >
    > Dim col As DataGridColumnStyle
    > col =
    >

    Me.DataGrid1.TableStyles("YourTableStyle").GridColumnStyles("YourColumnName"
    > )
    > col.Width = new value
    >
    > If you are filling the dataset programmatically, you will need to set a

    flag
    > after creating the TableStyle because the Forms first resize event fires
    > before the form is shown (ie the TableStyle will not exist), then put the
    > above code in an If statement
    >
    > If bolFlag = True Then
    > set column widths here
    > End if
    >
    > It may be preferable to put this code in the DataGrids Layout event. This
    > will prevent users from resizing the columns you have set.
    >
    > The only problem is that you need to take into account the possibility

    that
    > the vertical scroll bar will be visible. Unfortunately, the datagrid
    > ClientRectangle property also seems to include the scrollbars (unlike say
    > the ListView control). This means you have to finish the last column about
    > 22 pixels from the RHS of the control. Hopefully someone else has the
    > solution to this.
    >
    > Stephen Muecke
    >
    > "Russ Suter" <russ.suter@cox.net> wrote in message
    > news:3cf69963$1@10.1.10.29...
    > >
    > > I'm no slouch when it comes to VB programming but I can't seem to find

    out
    > > how to use code to resize columns in a datagrid control. I have my

    control
    > > bound to a typed dataset which creates 6 columns for the database info.

    > What
    > > I really need to do is resize the columns in the DataGrid's resize event
    > > so that there is no wasted space at the end of the table. Can anyone

    help
    > > me figure out how to do this?
    > >
    > > Thanks,
    > >
    > > Russ...
    > >
    > > P.S. If anyone can also tell me where I need to intercept an event so

    that
    > > I can post an update AS SOON AS a cell is changed, I'd very much

    > appreciate
    > > it.

    >
    >




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center