Advertisement

07.17.2008 at 07:40PM PDT, ID: 23575645
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.1

How do I change column widths in a .net datagrid

Asked by neil438 in .Net Compact Framework, Windows MobileProgramming, .NET Framework 3.x versions

I am creating a .net form which uses a datagrid.  The datagrid uses a datatable to get its data from.  There are 5 columns in the datatable and I want to individual size each of the column widths based upon maximum data size.  I would also like to be able to wordwrap the column headings so that the column heading can be more descriptive of the data in the columns.Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
Option Explicit On
Public Class yardstorageform
    ' declaration of yardstortab as a datatable
    ' this will be used to connect the datagrid
    Private yardstoretab As Data.DataTable
    Dim downstore As Integer
    Public yard10 As Decimal
    Public yard1 As Decimal
    Public yard_dec As Decimal
    Public totyards As Decimal
    Public yard10ltg As Decimal
    Public yard1ltg As Decimal
    Public yard_decltg As Decimal
    Public totyardsltg As Decimal
    Public team_in_possws As String
    Public team_yardws As String
    Public teamltg_yardws As String
    Public actyardline As Decimal
    Public actltgyardline As Decimal
    Public yards_to_1st As Integer
    Private Sub yardstorageform_Activated(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Activated
        ' Retrieves info from downandyardline form
        If downandyardline.RadioButton1.Checked = True Then
            downstore = 1
        Else
            If downandyardline.RadioButton3.Checked = True Then
                downstore = 2
            Else
                If downandyardline.RadioButton2.Checked = True Then
                    downstore = 3
                Else
                    downstore = 4
                End If
            End If
        End If
        'Converts yardline and line to gain info into real numbers
        yard10 = downandyardline.tenyardcombo.Text
        yard1 = downandyardline.oneyardcombo.Text
        yard_dec = downandyardline.decimalcombo.Text
        totyards = (yard10 + yard1 + yard_dec)
        team_in_possws = downandyardline.teampossesion.Text
        team_yardws = downandyardline.teamcombo.Text
        teamltg_yardws = downandyardline.ltgteam.Text
        yard10ltg = downandyardline.ltgtenyardcombo.Text
        yard1ltg = downandyardline.ltgoneyardcombo.Text
        yard_decltg = downandyardline.ltgdecimalcombo.Text
        totyardsltg = (yard10ltg + yard1ltg + yard_decltg)
        ' Calculates yards to 1st down
        If team_in_possws = team_yardws Then
            actyardline = totyards
        Else
            actyardline = (50 - totyards) + 50
        End If
        If downstore = 1 Then
            If team_in_possws = teamltg_yardws Then
                actltgyardline = totyardsltg
            Else
                actltgyardline = (50 - totyardsltg) + 50
            End If
        End If
        yards_to_1st = actltgyardline - actyardline
        ' set up a Data Row
        Dim MyRow As Data.DataRow
        If downandyardline.curr_row_cnt = downandyardline.row_cnt Then
            ' adds data to the table
            MyRow = yardstoretab.NewRow()
            ' index on MyRow is the cell number
            MyRow(0) = downstore
            MyRow(1) = team_in_possws
            MyRow(2) = team_yardws
            MyRow(3) = totyards
            MyRow(4) = yards_to_1st
            ' add row to table - index is the row number
            yardstoretab.Rows.InsertAt(MyRow, downandyardline.row_cnt)
            ' display the datagrid
            yardstoregrid.DataSource = yardstoretab
            yardstoregrid.Refresh()
            downandyardline.row_cnt = (downandyardline.row_cnt + 1)
        End If
    End Sub
    Private Sub yardstorageform_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' instantiates the data table in the storage form load 
        ' to maintain state
 
 
        yardstoretab = New Data.DataTable
        ' code used to load table styles.  This allows 
        ' formatting on yardstoregrid
        Dim tableStyle As New DataGridTableStyle
        ' next line is to set up column format
        Dim Col1 As New DataGridTextBoxColumn
        Col1.Width = 15
        ' next line matches to the column name in yardstoretab
        Col1.MappingName = "D"
        ' defines the column header for this column
        Col1.HeaderText = "D"
        Dim Col2 As New DataGridTextBoxColumn
        Col2.Width = 70
        ' next line matches to the column name in yardstoretab
        Col2.MappingName = "Team in Poss"
        ' defines the column header for this column
        Col2.HeaderText = "Team in Poss"
        Dim Col3 As New DataGridTextBoxColumn
        Col3.Width = 70
        ' next line matches to the column name in yardstoretab
        Col3.MappingName = "Team Yardline"
        ' defines the column header for this column
        Col3.HeaderText = "Team Yardline"
        Dim Col4 As New DataGridTextBoxColumn
        Col4.Width = 30
        ' next line matches to the column name in yardstoretab
        Col4.MappingName = "Line"
        ' defines the column header for this column
        Col4.HeaderText = "Line"
        Dim Col5 As New DataGridTextBoxColumn
        Col5.Width = 30
        ' next line matches to the column name in yardstoretab
        Col5.MappingName = "To 1st"
        ' defines the column header for this column
        Col5.HeaderText = "To 1st"
        ' bind the gridcolumnstyle to the tablestyle
        tableStyle.GridColumnStyles.Add(Col1)
        tableStyle.GridColumnStyles.Add(Col2)
        tableStyle.GridColumnStyles.Add(Col3)
        tableStyle.GridColumnStyles.Add(Col4)
        tableStyle.GridColumnStyles.Add(Col5)
        ' bind the tablestyle to yardstoregrid
        yardstoregrid.TableStyles.Add(tableStyle)
        yardstoretab.Columns.Add(New Data.DataColumn("D", GetType(String)))
        yardstoretab.Columns.Add(New Data.DataColumn("Team in Poss", GetType(String)))
        yardstoretab.Columns.Add(New Data.DataColumn("Team Yardline", GetType(String)))
        yardstoretab.Columns.Add(New Data.DataColumn("Line", GetType(String)))
        yardstoretab.Columns.Add(New Data.DataColumn("To 1st", GetType(String)))
 
    End Sub
 
    Private Sub retrnbutton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles retrnbutton.Click
        downandyardline.Show()
        Me.Hide()
    End Sub
 
    Private Sub yardstoregrid_CurrentCellChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles yardstoregrid.CurrentCellChanged
        ' yardstoregrid.PreferredColumnWidth = 10
    End Sub
End Class
[+][-]07.18.2008 at 04:57AM PDT, ID: 22034710

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: .Net Compact Framework, Windows MobileProgramming, .NET Framework 3.x versions
Sign Up Now!
Solution Provided By: Dhaest
Participating Experts: 1
Solution Grade: A
 
 
[+][-]07.18.2008 at 04:58AM PDT, ID: 22034713

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.18.2008 at 04:58AM PDT, ID: 22034716

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628