Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB.NET
|
VB.NET General VB.NET discussions for issues that don't fall into other VB.NET forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 29th, 2005, 05:32 PM
Registered User
 
Join Date: Nov 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Tablestyle not working for datagrid

I'm trying to apply a tablestyle to a datagrid, but no matter what I do the tablestyle is not applied. Here is my tablestyle code:


    Private Sub setTableStyleCr()
        Dim tableStyle_1 As New DataGridTableStyle
        Dim tableColCr As DataGridTextBoxColumn

        tableStyle_1.MappingName = "CREDIT_RATING"

    tableColCr = New DataGridTextBoxColumn
        tableColCr.MappingName = "CREDIT_RATING_ID"
    tableColCr.HeaderText = "CREDIT_RATING_ID"
        tableColCr.Width = 200
        tableColCr.ReadOnly = True
        tableColCr.NullText = ""
        tableStyle_1.GridColumnStyles.Add(tableColCr)

        tableColCr = New DataGridTextBoxColumn
        tableColCr.MappingName = "CREDIT_SOURCE_ID"
        tableColCr.HeaderText = "CREDIT_SOURCE_ID"
        tableColCr.Width = 200
        tableColCr.ReadOnly = True
        tableColCr.NullText = ""
        tableStyle_1.GridColumnStyles.Add(tableColCr)

        tableColCr = New DataGridTextBoxColumn
        tableColCr.MappingName = "CREDIT_SOURCE"
        tableColCr.HeaderText = "CREDIT_SOURCE"
        tableColCr.Width = 200
        tableColCr.ReadOnly = True
        tableColCr.NullText = ""
        tableStyle_1.GridColumnStyles.Add(tableColCr)

        tableColCr = New DataGridTextBoxColumn
        tableColCr.MappingName = "CREDIT_RATING"
        tableColCr.HeaderText = "CREDIT_RATING"
        tableColCr.Width = 200
        tableColCr.ReadOnly = True
        tableColCr.NullText = ""
        tableStyle_1.GridColumnStyles.Add(tableColCr)

        tableColCr = New DataGridTextBoxColumn
        tableColCr.MappingName = "RATING_TERM"
        tableColCr.HeaderText = "RATING_TERM"
        tableColCr.Width = 200
        tableColCr.ReadOnly = True
        tableColCr.NullText = ""
        tableStyle_1.GridColumnStyles.Add(tableColCr)

        tableColCr = New DataGridTextBoxColumn
        tableColCr.MappingName = "RATING_TERM_NAME"
        tableColCr.HeaderText = "RATING_TERM_NAME"
        tableColCr.Width = 200
        tableColCr.ReadOnly = True
        tableColCr.NullText = ""
        tableStyle_1.GridColumnStyles.Add(tableColCr)
        tableStyle_2.GridColumnStyles.Add(tableColCr)
        tableStyle_3.GridColumnStyles.Add(tableColCr)

        tableColCr = New DataGridTextBoxColumn
        tableColCr.MappingName = "RATING_TYPE"
        tableColCr.HeaderText = "RATING_TYPE"
        tableColCr.Width = 200
        tableColCr.ReadOnly = True
        tableColCr.NullText = ""
        tableStyle_1.GridColumnStyles.Add(tableColCr)

        tableColCr = New DataGridTextBoxColumn
        tableColCr.MappingName = "RATING_TYPE_NAME"
        tableColCr.HeaderText = "RATING_TYPE_NAME"
        tableColCr.Width = 200
        tableColCr.ReadOnly = True
        tableColCr.NullText = ""
        tableStyle_1.GridColumnStyles.Add(tableColCr)

        tableColCr = New DataGridTextBoxColumn
        tableColCr.MappingName = "DESCRIPTION"
        tableColCr.HeaderText = "DESCRIPTION"
        tableColCr.Width = 200
        tableColCr.ReadOnly = True
        tableColCr.NullText = ""
        tableStyle_1.GridColumnStyles.Add(tableColCr)

        tableColCr = New DataGridTextBoxColumn
        tableColCr.MappingName = "CREDIT_RATING_LIMIT"
        tableColCr.HeaderText = "CREDIT_RATING_LIMIT"
        tableColCr.Width = 200
        tableColCr.ReadOnly = True
        tableColCr.NullText = ""
        tableStyle_1.GridColumnStyles.Add(tableColCr)

        dgRating_1.TableStyles.Add(tableStyle_1)
    End Sub

Here is my datagrid code:

   Private Sub SetDgRating(ByRef legalID As String, ByRef Index As DataGrid, ByRef recSet As ADODB.Recordset, _
    ByRef dsCr As DataSet, ByRef daCr As OleDb.OleDbDataAdapter)
        Dim strInsert As String

        If legalID = "Please Select" Then
            Index.DataSource = Nothing
        ElseIf loadFlag Then
            Exit Sub
        Else
            recSet = New ADODB.Recordset
            strInsert = "SELECT A.FIELD1, A.FIELD2, B.FIELD3, A.FIELD4, A.FIELD5," _
        & " C.FIELD6, A.FIELD7, D.FIELD8, A.FIELD9, A.FIELD10" _
        & " FROM TABLE1 A, TABLE2 B, TABLE3 C, TABLE4 D" _
        & " WHERE A.FIELD1 = B.FIELD1 AND A.FIELD2 = C.FIELD2 AND A.FIELD3 = C.FIELD3 AND A.FIELD = '" _
        & legalID & "'"

            recSet.Open(strInsert, db, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)
            dsCr = New DataSet
            daCr = New OleDb.OleDbDataAdapter

            daCr.Fill(dsCr, recSet, "CREDIT_COUNTERPARTY_RATING")
            'Index.Refresh()
            Index.DataSource = dsCr
            Index.NavigateTo(0, "CREDIT_COUNTERPARTY_RATING")

        End If
    End Sub

I call the setTableStyleCr sub on load. Thanks for any hints anyone might have.

 
Old November 30th, 2005, 04:54 AM
Authorized User
 
Join Date: Nov 2005
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This is how I use to to it before I moved over onto VB.Vet 2005. Just copy and paste my code and adjust the db source, sql query and table styles.

Please let me know how u get on.

Pete*
__________________________________________________ _____________________

    'POPULATE DATAGRID
    Public Sub Load_Datagrid()
        Dim TableStyle As New DataGridTableStyle
        Dim DT As DataTable = New DataTable

        Dim Con As OleDb.OleDbConnection = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OleD b.4.0;data source=" & Database & "")
        Dim DA As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter("SELECT [Stock Code], [Description], [Sell], [Cost] FROM tbProdDesc ORDER BY [Category] Asc", Con)

        DA.Fill(DT).ToString()
        Dim column As New DataGridTextBoxColumn
        column.MappingName = "Stock Code"
        column.HeaderText = "Stock Code"
        column.Width = 75
        tableStyle.GridColumnStyles.Add(column)

        column = New DataGridTextBoxColumn
        column.MappingName = "Description"
        column.HeaderText = "Description"
        column.Width = 185
        tableStyle.GridColumnStyles.Add(column)

        column = New DataGridTextBoxColumn
        column.MappingName = "Cost"
        column.HeaderText = "Cost"
        column.Width = 65
        tableStyle.GridColumnStyles.Add(column)

        column = New DataGridTextBoxColumn
        column.MappingName = "Sell"
        column.HeaderText = "Sell"
        column.Width = 65
        tableStyle.GridColumnStyles.Add(column)

        DtgStock.TableStyles.Add(TableStyle)
        DtgStock.DataSource = DT 'Attach DataTable to DataGrid
__________________________________________________ ______________________
 
Old November 30th, 2005, 04:09 PM
Registered User
 
Join Date: Nov 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That worked. Thanks!

 
Old November 30th, 2005, 05:43 PM
Authorized User
 
Join Date: Nov 2005
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

No Probs ;)





Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP.Net Datagrid:-My Code is not working sibajibasak General .NET 2 January 22nd, 2005 01:50 AM
Losing Datagrid Content when Adding TableStyle SupaHoopsa General .NET 2 September 24th, 2004 02:50 AM
Hyperlink column in datagrid not working ltdanp21 General .NET 1 July 13th, 2004 03:04 PM
Validators not working in DataGrid swanand VS.NET 2002/2003 0 September 9th, 2003 06:15 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.