DataGrid Style

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Daniel

    #1

    DataGrid Style

    Hi all. Help! What am I doing wrong? My datagrid works fine, the
    columns are created and the data is filled. However, I just cannot
    resize the column widths to what I want them to be. I created a
    TableStyle but it is ignored. :-(

    I am using this code:


    Dim DS As New DataSet
    Dim MyTable As New DataTable
    Dim Col0 As New DataColumn
    Dim Col1 As New DataColumn
    Dim Col2 As New DataColumn

    DS.Tables.Add(0 )
    DS.Tables(0).Co lumns.Add(Col0)
    DS.Tables(0).Co lumns(0).Column Name = "Checked"
    DS.Tables(0).Co lumns.Add(Col1)
    DS.Tables(0).Co lumns(1).Column Name = "Path"
    DS.Tables(0).Co lumns.Add(Col2)
    DS.Tables(0).Co lumns(2).Column Name = "Node"


    Dim newRow As DataRow

    newRow = DS.Tables(0).Ne wRow
    newRow.Item("Ch ecked") = False
    newRow.Item("Pa th") = datSplit(0)
    newRow.Item("No de") = NodeName

    DS.Tables(0).Ro ws.Add(ErrRow)

    myDataGrid.Data Source = DS
    myDataGrid.SetD ataBinding(DS, DS.Tables(0).To String)


    --

    Daniel
    MCSE, MCP+I, MCP in Windows 2000/NT

    --------------------------------------
    remove the 2nd madrid from my mail address to contact me.
  • Ken Tucker [MVP]

    #2
    Re: DataGrid Style

    Hi,

    I dont see any code where you added a tablestyle to your grid.

    Here is an example.

    Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
    System.EventArg s) Handles MyBase.Load

    Dim conn As OleDbConnection

    Dim strConn As String

    Dim strSQL As String

    Dim ds As New DataSet

    Dim daCustomers As OleDbDataAdapte r

    strConn = "Provider = Microsoft.Jet.O LEDB.4.0;"

    strConn += "Data Source = C:\Northwind.md b;"

    conn = New OleDbConnection (strConn)

    daCustomers = New OleDbDataAdapte r("Select * from Customers", conn)

    daCustomers.Fil l(ds, "Customers" )

    SetupGrid()



    DataGrid1.DataS ource = ds.Tables("Cust omers")

    End Sub

    Private Sub SetupGrid()

    Dim ts As New DataGridTableSt yle

    ts.MappingName = "Customers"

    Dim colName As New DataGridTextBox Column

    With colName

    ..MappingName = "ContactNam e"

    ..HeaderText = "Name"

    ..Width = 150

    End With


    Dim colID As New DataGridTextBox Column

    With colID

    ..MappingName = "CustomerID "

    ..HeaderText = "ID"

    ..Width = 80

    End With

    Dim colRegion As New DataGridTextBox Column

    With colRegion

    ..MappingName = "Region"

    ..HeaderText = "Region"

    ..Width = 80

    ..NullText = ""

    End With

    ts.GridColumnSt yles.Add(colID)

    ts.GridColumnSt yles.Add(colNam e)

    ts.GridColumnSt yles.Add(colReg ion)

    DataGrid1.Table Styles.Add(ts)

    ts = Nothing

    colRegion = Nothing

    colName = Nothing

    colID = Nothing

    End Sub

    Ken
    --------------------------
    "Daniel" <daniel@madridm adridsoleado.co m> wrote in message
    news:%23EbyHNyc FHA.720@TK2MSFT NGP15.phx.gbl.. .
    Hi all. Help! What am I doing wrong? My datagrid works fine, the
    columns are created and the data is filled. However, I just cannot
    resize the column widths to what I want them to be. I created a
    TableStyle but it is ignored. :-(

    I am using this code:


    Dim DS As New DataSet
    Dim MyTable As New DataTable
    Dim Col0 As New DataColumn
    Dim Col1 As New DataColumn
    Dim Col2 As New DataColumn

    DS.Tables.Add(0 )
    DS.Tables(0).Co lumns.Add(Col0)
    DS.Tables(0).Co lumns(0).Column Name = "Checked"
    DS.Tables(0).Co lumns.Add(Col1)
    DS.Tables(0).Co lumns(1).Column Name = "Path"
    DS.Tables(0).Co lumns.Add(Col2)
    DS.Tables(0).Co lumns(2).Column Name = "Node"


    Dim newRow As DataRow

    newRow = DS.Tables(0).Ne wRow
    newRow.Item("Ch ecked") = False
    newRow.Item("Pa th") = datSplit(0)
    newRow.Item("No de") = NodeName

    DS.Tables(0).Ro ws.Add(ErrRow)

    myDataGrid.Data Source = DS
    myDataGrid.SetD ataBinding(DS, DS.Tables(0).To String)


    --

    Daniel
    MCSE, MCP+I, MCP in Windows 2000/NT

    --------------------------------------
    remove the 2nd madrid from my mail address to contact me.


    Comment

    • Daniel

      #3
      Re: DataGrid Style

      Ken Tucker [MVP] wrote:[color=blue]
      > Hi,
      >
      > I dont see any code where you added a tablestyle to your grid.
      >
      > Here is an example.
      >
      > Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
      > System.EventArg s) Handles MyBase.Load
      >
      > Dim conn As OleDbConnection
      >
      > Dim strConn As String
      >
      > Dim strSQL As String
      >
      > Dim ds As New DataSet
      >
      > Dim daCustomers As OleDbDataAdapte r
      >
      > strConn = "Provider = Microsoft.Jet.O LEDB.4.0;"
      >
      > strConn += "Data Source = C:\Northwind.md b;"
      >
      > conn = New OleDbConnection (strConn)
      >
      > daCustomers = New OleDbDataAdapte r("Select * from Customers", conn)
      >
      > daCustomers.Fil l(ds, "Customers" )
      >
      > SetupGrid()
      >
      >
      >
      > DataGrid1.DataS ource = ds.Tables("Cust omers")
      >
      > End Sub
      >
      > Private Sub SetupGrid()
      >
      > Dim ts As New DataGridTableSt yle
      >
      > ts.MappingName = "Customers"
      >
      > Dim colName As New DataGridTextBox Column
      >
      > With colName
      >
      > ..MappingName = "ContactNam e"
      >
      > ..HeaderText = "Name"
      >
      > ..Width = 150
      >
      > End With
      >
      >
      > Dim colID As New DataGridTextBox Column
      >
      > With colID
      >
      > ..MappingName = "CustomerID "
      >
      > ..HeaderText = "ID"
      >
      > ..Width = 80
      >
      > End With
      >
      > Dim colRegion As New DataGridTextBox Column
      >
      > With colRegion
      >
      > ..MappingName = "Region"
      >
      > ..HeaderText = "Region"
      >
      > ..Width = 80
      >
      > ..NullText = ""
      >
      > End With
      >
      > ts.GridColumnSt yles.Add(colID)
      >
      > ts.GridColumnSt yles.Add(colNam e)
      >
      > ts.GridColumnSt yles.Add(colReg ion)
      >
      > DataGrid1.Table Styles.Add(ts)
      >
      > ts = Nothing
      >
      > colRegion = Nothing
      >
      > colName = Nothing
      >
      > colID = Nothing
      >
      > End Sub
      >
      > Ken
      > --------------------------
      > "Daniel" <daniel@madridm adridsoleado.co m> wrote in message
      > news:%23EbyHNyc FHA.720@TK2MSFT NGP15.phx.gbl.. .
      > Hi all. Help! What am I doing wrong? My datagrid works fine, the
      > columns are created and the data is filled. However, I just cannot
      > resize the column widths to what I want them to be. I created a
      > TableStyle but it is ignored. :-(
      >
      > I am using this code:
      >
      >
      > Dim DS As New DataSet
      > Dim MyTable As New DataTable
      > Dim Col0 As New DataColumn
      > Dim Col1 As New DataColumn
      > Dim Col2 As New DataColumn
      >
      > DS.Tables.Add(0 )
      > DS.Tables(0).Co lumns.Add(Col0)
      > DS.Tables(0).Co lumns(0).Column Name = "Checked"
      > DS.Tables(0).Co lumns.Add(Col1)
      > DS.Tables(0).Co lumns(1).Column Name = "Path"
      > DS.Tables(0).Co lumns.Add(Col2)
      > DS.Tables(0).Co lumns(2).Column Name = "Node"
      >
      >
      > Dim newRow As DataRow
      >
      > newRow = DS.Tables(0).Ne wRow
      > newRow.Item("Ch ecked") = False
      > newRow.Item("Pa th") = datSplit(0)
      > newRow.Item("No de") = NodeName
      >
      > DS.Tables(0).Ro ws.Add(ErrRow)
      >
      > myDataGrid.Data Source = DS
      > myDataGrid.SetD ataBinding(DS, DS.Tables(0).To String)
      >
      >[/color]
      Thanks for this however i get the error "The data grid table styles
      collection already contains a table style with the same mapping name"

      This is because I have already created the tablestyle via the properties
      of the datagrid in the IDE. My problem is that the style I created is
      ignored! Any ideas?

      --

      Daniel
      MCSE, MCP+I, MCP in Windows 2000/NT

      --------------------------------------
      remove the 2nd madrid from my mail address to contact me.

      Comment

      • Daniel

        #4
        Re: DataGrid Style

        Daniel wrote:[color=blue]
        > Ken Tucker [MVP] wrote:
        >[color=green]
        >> Hi,
        >>
        >> I dont see any code where you added a tablestyle to your
        >> grid.
        >>
        >> Here is an example.
        >>
        >> Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
        >> System.EventArg s) Handles MyBase.Load
        >>
        >> Dim conn As OleDbConnection
        >>
        >> Dim strConn As String
        >>
        >> Dim strSQL As String
        >>
        >> Dim ds As New DataSet
        >>
        >> Dim daCustomers As OleDbDataAdapte r
        >>
        >> strConn = "Provider = Microsoft.Jet.O LEDB.4.0;"
        >>
        >> strConn += "Data Source = C:\Northwind.md b;"
        >>
        >> conn = New OleDbConnection (strConn)
        >>
        >> daCustomers = New OleDbDataAdapte r("Select * from Customers", conn)
        >>
        >> daCustomers.Fil l(ds, "Customers" )
        >>
        >> SetupGrid()
        >>
        >>
        >>
        >> DataGrid1.DataS ource = ds.Tables("Cust omers")
        >>
        >> End Sub
        >>
        >> Private Sub SetupGrid()
        >>
        >> Dim ts As New DataGridTableSt yle
        >>
        >> ts.MappingName = "Customers"
        >>
        >> Dim colName As New DataGridTextBox Column
        >>
        >> With colName
        >>
        >> ..MappingName = "ContactNam e"
        >>
        >> ..HeaderText = "Name"
        >>
        >> ..Width = 150
        >>
        >> End With
        >>
        >>
        >> Dim colID As New DataGridTextBox Column
        >>
        >> With colID
        >>
        >> ..MappingName = "CustomerID "
        >>
        >> ..HeaderText = "ID"
        >>
        >> ..Width = 80
        >>
        >> End With
        >>
        >> Dim colRegion As New DataGridTextBox Column
        >>
        >> With colRegion
        >>
        >> ..MappingName = "Region"
        >>
        >> ..HeaderText = "Region"
        >>
        >> ..Width = 80
        >>
        >> ..NullText = ""
        >>
        >> End With
        >>
        >> ts.GridColumnSt yles.Add(colID)
        >>
        >> ts.GridColumnSt yles.Add(colNam e)
        >>
        >> ts.GridColumnSt yles.Add(colReg ion)
        >>
        >> DataGrid1.Table Styles.Add(ts)
        >>
        >> ts = Nothing
        >>
        >> colRegion = Nothing
        >>
        >> colName = Nothing
        >>
        >> colID = Nothing
        >>
        >> End Sub
        >>
        >> Ken
        >> --------------------------
        >> "Daniel" <daniel@madridm adridsoleado.co m> wrote in message
        >> news:%23EbyHNyc FHA.720@TK2MSFT NGP15.phx.gbl.. .
        >> Hi all. Help! What am I doing wrong? My datagrid works fine, the
        >> columns are created and the data is filled. However, I just cannot
        >> resize the column widths to what I want them to be. I created a
        >> TableStyle but it is ignored. :-(
        >>
        >> I am using this code:
        >>
        >>
        >> Dim DS As New DataSet
        >> Dim MyTable As New DataTable
        >> Dim Col0 As New DataColumn
        >> Dim Col1 As New DataColumn
        >> Dim Col2 As New DataColumn
        >>
        >> DS.Tables.Add(0 )
        >> DS.Tables(0).Co lumns.Add(Col0)
        >> DS.Tables(0).Co lumns(0).Column Name = "Checked"
        >> DS.Tables(0).Co lumns.Add(Col1)
        >> DS.Tables(0).Co lumns(1).Column Name = "Path"
        >> DS.Tables(0).Co lumns.Add(Col2)
        >> DS.Tables(0).Co lumns(2).Column Name = "Node"
        >>
        >>
        >> Dim newRow As DataRow
        >>
        >> newRow = DS.Tables(0).Ne wRow
        >> newRow.Item("Ch ecked") = False
        >> newRow.Item("Pa th") = datSplit(0)
        >> newRow.Item("No de") = NodeName
        >>
        >> DS.Tables(0).Ro ws.Add(ErrRow)
        >>
        >> myDataGrid.Data Source = DS
        >> myDataGrid.SetD ataBinding(DS, DS.Tables(0).To String)
        >>
        >>[/color]
        > Thanks for this however i get the error "The data grid table styles
        > collection already contains a table style with the same mapping name"
        >
        > This is because I have already created the tablestyle via the properties
        > of the datagrid in the IDE. My problem is that the style I created is
        > ignored! Any ideas?
        >[/color]
        It is OK, I worked it out. I binned the tablestyle that i made in the
        IDE and just created it via code and it works. 1 line i missed though
        was "MyTS.MappingNa me = mYTable.GetType ().Name" where MyTS is the New
        TableStyle.

        --

        Daniel
        MCSE, MCP+I, MCP in Windows 2000/NT

        --------------------------------------
        remove the 2nd madrid from my mail address to contact me.

        Comment

        Working...