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. Problem with DataGridView

Problem with DataGridView

Scheduled Pinned Locked Moved Visual Basic
helpcssdatabase
4 Posts 2 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.
  • J Offline
    J Offline
    Jack Brando
    wrote on last edited by
    #1

    Good day! I have a problem using DataGridView. Here's my code. Public Class MyLibrary Private _dgv As DataGridView Private _recordBLL As RecordBLL Private _dt As DataTable Public Sub New() Me._dgv = New DataGridView Me._recordBLL = New RecordBLL Me._dt = New DataTable Me._dt = recordBLL.PrincipalMember Me._dgv.DataSource = dt '********* Error is displaying here ******** With Me._dgv .Columns(0).Visible = False .Columns(1).Width = 200 .Columns(2).Width = 600 .Columns(3).Width = 150 .Columns(3).DefaultCellStyle.Format = "MM/dd/yyyy" End With End Sub ReadOnly Property MyDataGridView() As DataGridView Get Return _dgv End Get End Property End Class And I encountered this error. "Index was out of range. Must be non-negative and less than the size of the collection." But the data is displayed in the grid. Pls. help me. Thank you in advance.

    C 1 Reply Last reply
    0
    • J Jack Brando

      Good day! I have a problem using DataGridView. Here's my code. Public Class MyLibrary Private _dgv As DataGridView Private _recordBLL As RecordBLL Private _dt As DataTable Public Sub New() Me._dgv = New DataGridView Me._recordBLL = New RecordBLL Me._dt = New DataTable Me._dt = recordBLL.PrincipalMember Me._dgv.DataSource = dt '********* Error is displaying here ******** With Me._dgv .Columns(0).Visible = False .Columns(1).Width = 200 .Columns(2).Width = 600 .Columns(3).Width = 150 .Columns(3).DefaultCellStyle.Format = "MM/dd/yyyy" End With End Sub ReadOnly Property MyDataGridView() As DataGridView Get Return _dgv End Get End Property End Class And I encountered this error. "Index was out of range. Must be non-negative and less than the size of the collection." But the data is displayed in the grid. Pls. help me. Thank you in advance.

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Well, I guess you don't have four columns at the point that this code is run. What makes you think that you do ?

      Christian Graus Driven to the arms of OSX by Vista. "! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums. I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp

      J 1 Reply Last reply
      0
      • C Christian Graus

        Well, I guess you don't have four columns at the point that this code is run. What makes you think that you do ?

        Christian Graus Driven to the arms of OSX by Vista. "! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums. I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp

        J Offline
        J Offline
        Jack Brando
        wrote on last edited by
        #3

        I already bound the grid with datatable and the result reflect in my datagridview control. And I saw the columns and rows. Do you mean I need to create set of columns and bind it with datatable? Thank you very much to your reply.

        C 1 Reply Last reply
        0
        • J Jack Brando

          I already bound the grid with datatable and the result reflect in my datagridview control. And I saw the columns and rows. Do you mean I need to create set of columns and bind it with datatable? Thank you very much to your reply.

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          No, if you have databound, then you should just have the columns. However, it's clear you do not, that's what the error means. So, you need to work out why, that's what your issue is. Which line blows up ( that is, do you have any columns at all ? )

          Christian Graus Driven to the arms of OSX by Vista. "! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums. I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp

          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