Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Row Height in DataGrid Control...?
Message
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
VB.NET 1.1
OS:
Windows 2000 SP4
Network:
Windows 2000 Server
Miscellaneous
Thread ID:
01077085
Message ID:
01077109
Views:
27
Here is the code I am using. Please note that I am new to VB.Net and this is the only way I found that I can accomplish what I am looking for. I know there is probably a better way, but I am pressed for time and just need to get this working. Before you see the code, I'll give you some backgound. I have a polymorphic form where I need to display certain columns as Combobox/Dropdown Lists. I saw that VB.Net does not have a "DataGridComboBoxColumn" type, so I searched online and found an article saying that the only way was to "fake" it by creating a Combobox object, and just display it over the selected cell. I got most of the code working, except that my Combobox is taller then the row, so I need to increase to row height. Now that you have the background....here is my code.
Private Sub FormatGrid()
        '************************************************************************
        ' Procedure/Function: FormatGrid()
        ' Author: Ben Santiago
        ' Last Revision: 12/09/2005
        ' Description:
        '       Format grid based on supplied schema.
        '
        ' Schema for GridFormatString:
        '       ColumnName=HeaderName=Width=Type,ColumnName=HeaderName=Width=Type,etc...
        '           Width: Numeric Value Causes Override To Specified Size
        '           Type:  Text, Combo
        '************************************************************************

        '***************************************
        ' Initialize Variables
        '***************************************
        Dim objComboDef As structComboData
        Dim objTableStyle As New DataGridTableStyle
        Dim objColumnStyle As DataGridTextBoxColumn
        Dim objFont As New Font(gridListing.Font.Name, gridListing.Font.Size, gridListing.Font.Style)
        Dim objBitmap As New Bitmap(1, 1)
        Dim objGraphics As Graphics = Graphics.FromImage(objBitmap)
        Dim arrColumnDefinitions() As String
        Dim arrColumnDetails() As String
        Dim intCounter As Short

        '***************************************
        ' Parse String Into Array
        ' Process Each Column Definition
        '***************************************
        arrColumnDefinitions = GridFormatString.Split(",")
        For intCounter = 0 To arrColumnDefinitions.GetUpperBound(0)
            '***************************************
            ' Parse Column Details
            '   0 = Column Name
            '   1 = Column Header Text
            '   2 = Column Width
            '   3 = Column Type
            '***************************************
            ReDim Preserve arrColumnDetails(3)
            Array.Clear(arrColumnDetails, 0, 4)
            arrColumnDetails = arrColumnDefinitions(intCounter).Split("=")
            ReDim Preserve arrColumnDetails(3)

            '***************************************
            ' Set Defaults (If Needed)
            '***************************************
            If arrColumnDetails(2) = "" Then
                arrColumnDetails(2) = "*"
            End If
            If arrColumnDetails(3) = "" Then
                arrColumnDetails(3) = "Text"
            End If

            '***************************************
            ' Create Table Style
            '***************************************
            With objTableStyle
                '***************************************
                ' Define General Style Properties
                '***************************************
                .MappingName = "tblListing"
                .RowHeadersVisible = False

                '***************************************
                ' Define Column Properties
                '***************************************
                objColumnStyle = New DataGridTextBoxColumn
                With objColumnStyle
                    .MappingName = arrColumnDetails(0)
                    .HeaderText = arrColumnDetails(1)
                    If arrColumnDetails(2) = "*" Then
                        .Width = objGraphics.MeasureString(.HeaderText, objFont).Width + 5
                    Else
                        .Width = arrColumnDetails(2)
                    End If
                End With
                .GridColumnStyles.Add(objColumnStyle)

                '***************************************
                ' If Designated As Combo, Create Object
                '***************************************
                If arrColumnDetails(3).ToUpper = "COMBO" Then
                    '***************************************
                    ' Create Object & Handler Reference
                    '***************************************
                    objComboDef = Me.ComboboxDefinitions(arrColumnDetails(0))
                    objComboDef.objCombobox.DropDownStyle = ComboBoxStyle.DropDownList
                    objComboDef.objCombobox.Visible = False
                    AddHandler objComboDef.objCombobox.TextChanged, AddressOf ComboTextChanged

                    '***************************************
                    ' Populate Combobox With Data
                    '***************************************
                    objDatabase.OpenTable(Me.FormID, "tbl" & arrColumnDetails(0), objComboDef.SQLStatement)
                    With objComboDef.objCombobox
                        .DataSource = objDatabase.DataSets(Me.FormID).Tables("tbl" & arrColumnDetails(0))
                        .DisplayMember = objComboDef.DisplayColumn
                        .ValueMember = objComboDef.ValueColumn
                    End With

                    '***************************************
                    ' Add Combobox To Grid
                    '***************************************
                    gridListing.Controls.Add(objComboDef.objCombobox)
                End If
            End With
        Next

        '***************************************
        ' Define Grid Style Properties
        '***************************************
        With gridListing
            .CaptionVisible = False
            .RowHeadersVisible = False
        End With

        '***************************************
        ' Apply Table Style To Grid
        '***************************************
        gridListing.TableStyles.Add(objTableStyle)

        '***************************************
        ' Load Data
        '***************************************
        If Not objComboDef Is Nothing Then
            gridListing.PreferredRowHeight = objComboDef.objCombobox.Height + 10
        End If
        LoadData()

        '***************************************
        ' Refresh/Reset Currently Selected Cell
        '***************************************
        gridListing.CurrentCell = New DataGridCell(0, 1)
        gridListing.CurrentCell = New DataGridCell(0, 0)
    End Sub
________________________
Ben Santiago, MCP & A+
Programmer Analyst (SQL, FoxPro, VB, VB.Net, Java, HTML, ASP, JSP, VBS)
Eastern Suffolk BOCES - Student Data Services


Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
-Rich Cook
Previous
Reply
Map
View

Click here to load this message in the networking platform