Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. DataGrid Error - Need help

DataGrid Error - Need help

Scheduled Pinned Locked Moved Visual Basic
helpcsstutorial
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    ibok23
    wrote on last edited by
    #1

    I have added a data grid. I am trying to change the default header of each column to another name. For example:

    dgtsPayrollInfo.GridColumnStyles(0).HeaderText = "Employee ID"
    dgtsPayrollInfo.GridColumnStyles(0).Alignment = HorizontalAlignment.Center

    I keep getting an error. I want my first column to have employee id as the header. Any Sugggestion Thank you, ibok23

    D U 2 Replies Last reply
    0
    • I ibok23

      I have added a data grid. I am trying to change the default header of each column to another name. For example:

      dgtsPayrollInfo.GridColumnStyles(0).HeaderText = "Employee ID"
      dgtsPayrollInfo.GridColumnStyles(0).Alignment = HorizontalAlignment.Center

      I keep getting an error. I want my first column to have employee id as the header. Any Sugggestion Thank you, ibok23

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      ibok23 wrote: I keep getting an error. And that error would be ....? RageInTheMachine9532

      I 1 Reply Last reply
      0
      • I ibok23

        I have added a data grid. I am trying to change the default header of each column to another name. For example:

        dgtsPayrollInfo.GridColumnStyles(0).HeaderText = "Employee ID"
        dgtsPayrollInfo.GridColumnStyles(0).Alignment = HorizontalAlignment.Center

        I keep getting an error. I want my first column to have employee id as the header. Any Sugggestion Thank you, ibok23

        U Offline
        U Offline
        User 765502
        wrote on last edited by
        #3

        Dim GridTableStyle1 As New DataGridTableStyle() GridTableStyle1.MappingName = "Customer" 'Customer is the name of the table in the dataset Dim GridColStyle1 As New DataGridTextBoxColumn() With GridColStyle1 .HeaderText = "ID" .MappingName = "CustID" End With GridTableStyle1.GridColumnStyles.Add(GridColStyle1) MyDataGrid.TableStyles.Add(GridTableStyle1)

        1 Reply Last reply
        0
        • D Dave Kreskowiak

          ibok23 wrote: I keep getting an error. And that error would be ....? RageInTheMachine9532

          I Offline
          I Offline
          ibok23
          wrote on last edited by
          #4

          I am trying to put a header on each of my columns in my data grid. I have the columns already there, but with a different name from when I made the data relations. For example on column one it has "fldEmployeeId". I just want "Employee ID". I am getting an error while trying to run it. It is telling me that An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dllAdditional information: Index was out of range. Must be non-negative and less than the size of the collection. The error is on the first line in this part of the code. What am I doing wrong? I have a total of 6 columns. Any suggestions.

          dgPayrollInfo.GridColumnStyles(0).HeaderText = "Employee ID"
          dgPayrollInfo.GridColumnStyles(0).Alignment = HorizontalAlignment.Center
          dgPayrollInfo.GridColumnStyles(1).HeaderText = "Payroll ID"
          dgPayrollInfo.GridColumnStyles(1).Alignment = HorizontalAlignment.Center
          dgPayrollInfo.GridColumnStyles(2).HeaderText = "Pay Date"
          dgPayrollInfo.GridColumnStyles(2).Alignment = HorizontalAlignment.Center
          dgPayrollInfo.GridColumnStyles(3).HeaderText = "Gross Pay"
          dgPayrollInfo.GridColumnStyles(3).Alignment = HorizontalAlignment.Right
          dgPayrollInfo.GridColumnStyles(4).HeaderText = "Withholding"
          dgPayrollInfo.GridColumnStyles(4).Alignment = HorizontalAlignment.Right
          dgPayrollInfo.GridColumnStyles(5).HeaderText = "Net Pay"
          dgPayrollInfo.GridColumnStyles(5).Alignment = HorizontalAlignment.Right

          Thank you, ibok23

          D 1 Reply Last reply
          0
          • I ibok23

            I am trying to put a header on each of my columns in my data grid. I have the columns already there, but with a different name from when I made the data relations. For example on column one it has "fldEmployeeId". I just want "Employee ID". I am getting an error while trying to run it. It is telling me that An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dllAdditional information: Index was out of range. Must be non-negative and less than the size of the collection. The error is on the first line in this part of the code. What am I doing wrong? I have a total of 6 columns. Any suggestions.

            dgPayrollInfo.GridColumnStyles(0).HeaderText = "Employee ID"
            dgPayrollInfo.GridColumnStyles(0).Alignment = HorizontalAlignment.Center
            dgPayrollInfo.GridColumnStyles(1).HeaderText = "Payroll ID"
            dgPayrollInfo.GridColumnStyles(1).Alignment = HorizontalAlignment.Center
            dgPayrollInfo.GridColumnStyles(2).HeaderText = "Pay Date"
            dgPayrollInfo.GridColumnStyles(2).Alignment = HorizontalAlignment.Center
            dgPayrollInfo.GridColumnStyles(3).HeaderText = "Gross Pay"
            dgPayrollInfo.GridColumnStyles(3).Alignment = HorizontalAlignment.Right
            dgPayrollInfo.GridColumnStyles(4).HeaderText = "Withholding"
            dgPayrollInfo.GridColumnStyles(4).Alignment = HorizontalAlignment.Right
            dgPayrollInfo.GridColumnStyles(5).HeaderText = "Net Pay"
            dgPayrollInfo.GridColumnStyles(5).Alignment = HorizontalAlignment.Right

            Thank you, ibok23

            D Offline
            D Offline
            Dave Kreskowiak
            wrote on last edited by
            #5

            You need to create the GridColumnStyle first, then added it to the GridColumStylesCollection. Just indexing a GridColumnStyleCollection, like your doing, will not create a new column.

            Dim newGridColumnStyle As New GridColumnStyle
            newGridColumnStyle.HeaderText = "Employee ID"
            newGridColumnStyle.Alignment = HorizontalAlignment.Center
            

            dgPayrollInfo.GridColumnStyles.Add( newGridColumStyle )
            .
            .
            .

            RageInTheMachine9532

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups