Avatar of javagair
javagairFlag for United States of America

asked on 

assigning dataset to gridview in vb.net

For i = 0 To Dstworkcounter2.Tables(0).Rows.Count - 1
       For j = 1 To 9
          DataGridView1.Item(j - 1, i).Value = Dstworkcounter2.Tables(0).Rows(i).Item(j).ToString
         Next
   Next
have a valid dataset, don't want the first value from it
get a run time error that says the index is either negative or out of range.
i is zero and j is one at that point.

I just want to fill the datagridview with data.  I remember something about turning off something in the datagridview properties.  
anyone got a idea why I just can't do a simple assign to a datagridview like this?

gary
Visual Basic.NET

Avatar of undefined
Last Comment
javagair
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Hi javagair;

You should be able to do this and the second line of code will remove the column from being displayed.

DataGridView1.DataSource = Dstworkcounter2.Tables(0)
DataGridView1.Columns.Remove("Replace With Column Name As String")

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Ark
Ark
Flag of Russian Federation image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of javagair
javagair
Flag of United States of America image

ASKER

I added one simple line after reading ark comments.
 i = 0
                For Each row As DataRow In Dst3.Tables(0).Rows


                    DataGridView1.Rows.Add(1) 'THIS SOLVED PROBLEM
                    For j = 1 To 9
                        DataGridView1.Item(j - 1, i).Value = Dst3.Tables(0).Rows(i).Item(j).ToString
                    Next
                    i = i + 1
                Next row
Visual Basic.NET
Visual Basic.NET

Visual Basic .NET (VB.NET) is an object-oriented programming language implemented on the .NET framework, but also supported on other platforms such as Mono and Silverlight. Microsoft launched VB.NET as the successor to the Visual Basic language. Though it is similar in syntax to Visual Basic pre-2002, it is not the same technology,

96K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo