PC Review


Reply
Thread Tools Rate Thread

Displaying DataGrid Rows

 
 
fripper
Guest
Posts: n/a
 
      13th Nov 2004
After getting some good help through this newsgroup I have finally figured
out one way to populate a DataGrid programmatically ... specifically by
using a Data Table, adding columns then rows to it and then binding it to
the DataGrid. Here is a simplified version of my code:

Dim DT as New DataTable
Dim DR as DataRow = DT.NewRow
DT.Columns.Add("Col. A")
DT.Columns.Add("Col. B")
For i = 1 to 3
Dim DRX as DataRow = DT.NewRow
DRX.Item(0) = i
DRX.Item(1) = 4 * i
DT.Rows.Add(DRX)
Next i
DataGridView1.DataSource = DT

When I run this code I only see the heading row [Col. A and Col. B] and one
detail row [with 1 in the first column and 4 in the second column]. I don't
understand why I don't see all three detail rows. Can someone explain this
and tell me where I am messing up?

Thanks very much.






 
Reply With Quote
 
 
 
 
james
Guest
Posts: n/a
 
      13th Nov 2004
You need to do this:
Dim i as Intger
in your dim statements and then it will work.
(just tried it to be sure)
james



"fripper" <(E-Mail Removed)> wrote in message news:%(E-Mail Removed)...
> After getting some good help through this newsgroup I have finally figured out one way to populate a DataGrid programmatically
> ... specifically by using a Data Table, adding columns then rows to it and then binding it to the DataGrid. Here is a
> simplified version of my code:
>
> Dim DT as New DataTable
> Dim DR as DataRow = DT.NewRow
> DT.Columns.Add("Col. A")
> DT.Columns.Add("Col. B")
> For i = 1 to 3
> Dim DRX as DataRow = DT.NewRow
> DRX.Item(0) = i
> DRX.Item(1) = 4 * i
> DT.Rows.Add(DRX)
> Next i
> DataGridView1.DataSource = DT
>
> When I run this code I only see the heading row [Col. A and Col. B] and one detail row [with 1 in the first column and 4 in
> the second column]. I don't understand why I don't see all three detail rows. Can someone explain this and tell me where I
> am messing up?
>
> Thanks very much.
>
>
>
>
>
>



 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      13th Nov 2004
fripper,

I tried your code because I did not understand why it would not work. It
does work in my opinion as it should it gives a column and a columnheader
and 3 rows of data.

However it is good when you set in the top of your files Option Strict On
and Option Explicit On you will be pointed on program errors and late
bindings. Without that VBNet acts often as VB6 and is therefore a lot
slower.

(The second row is not necassery, however does not give the error)

I hope this helps?

Cor


"fripper" <(E-Mail Removed)>

> After getting some good help through this newsgroup I have finally figured
> out one way to populate a DataGrid programmatically ... specifically by
> using a Data Table, adding columns then rows to it and then binding it to
> the DataGrid. Here is a simplified version of my code:
>
> Dim DT as New DataTable
> Dim DR as DataRow = DT.NewRow
> DT.Columns.Add("Col. A")
> DT.Columns.Add("Col. B")
> For i = 1 to 3
> Dim DRX as DataRow = DT.NewRow
> DRX.Item(0) = i
> DRX.Item(1) = 4 * i
> DT.Rows.Add(DRX)
> Next i
> DataGridView1.DataSource = DT
>
> When I run this code I only see the heading row [Col. A and Col. B] and
> one detail row [with 1 in the first column and 4 in the second column]. I
> don't understand why I don't see all three detail rows. Can someone
> explain this and tell me where I am messing up?
>
> Thanks very much.
>
>
>
>
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Displaying a datagrid X rows at a time quanga@gmail.com Microsoft ASP .NET 5 23rd Mar 2005 06:54 PM
displaying multiple rows in a datagrid =?Utf-8?B?R2VyYWxkaW5lIEhvYmxleQ==?= Microsoft VB .NET 1 18th Jun 2004 11:32 AM
datagrid scrolling...capturihng rows displayed in view of datagrid Patrick Microsoft Dot NET Framework Forms 3 7th Jun 2004 11:07 AM
searching a datagrid's rows and displaying rows where item was found Angel Microsoft C# .NET 0 26th Apr 2004 05:51 PM
DataGrid Component | Displaying columns of a DataSet as Rows in a DataGrid ? Diego TERCERO Microsoft C# .NET 3 19th Dec 2003 02:21 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:22 AM.