Solved

Dataview Column Width

Posted on 2004-08-14
5
452 Views
Last Modified: 2012-05-05
how do i set a datagrids column width if it is bound to a dataview?
0
Comment
Question by:daverichardson
  • 3
  • 2
5 Comments
 
LVL 4

Expert Comment

by:srcalc
ID: 11802675
The following code will set the width of a column named myColumnName in a table named myTableName to 25. I assume that your DataGrid is called DataGrid1.

        Dim ts As New DataGridTableStyle
        ts.MappingName = "myTableName"
        datagrid1.TableStyles.Add(ts)
        Dim cs As New DataGridTextBoxColumn
        cs.MappingName = "myColumnName"
        cs.Width = 25
        datagrid1.TableStyles(0).GridColumnStyles.Add(cs)

If you need the name of your table do this:

MsgBox(CType(datagrid1.DataSource, DataView).Table.TableName)
0
 
LVL 4

Accepted Solution

by:
srcalc earned 50 total points
ID: 11802677
Sorry you code would be more accurate like this:

        Dim ts As New DataGridTableStyle
        ts.MappingName = "myTableName"
        Dim cs As New DataGridTextBoxColumn
        cs.MappingName = "myColumnName"
        cs.Width = 25
        ts.GridColumnStyles.Add(cs)
        datagrid1.TableStyles.Add(ts)
0
 

Author Comment

by:daverichardson
ID: 11803438
That Works Great, for multiple column i have used

Dim ts As New DataGridTableStyle
        ts.MappingName = "tblstockusage"
        Dim cs As New DataGridTextBoxColumn
        cs.MappingName = "stockcode"
        cs.Width = 120
        cs.HeaderText = "Stock Code"
        ts.GridColumnStyles.Add(cs)

        Dim cs1 As New DataGridTextBoxColumn
        cs1.MappingName = "description"
        cs1.Width = 210
        cs1.HeaderText = "Description"
        ts.GridColumnStyles.Add(cs1)

        Dim cs2 As New DataGridTextBoxColumn
        cs2.MappingName = "SalesQty"
        cs2.Width = 50
        cs2.HeaderText = "Qty"
        ts.GridColumnStyles.Add(cs2)

Is that the best way?
0
 
LVL 4

Expert Comment

by:srcalc
ID: 11804538
It looks good to me
0
 

Author Comment

by:daverichardson
ID: 11807427
Thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now