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