473,387 Members | 1,669 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Displaying DataGrid Rows

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.


Nov 21 '05 #1
4 1255
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" <fr*****@insightbb.com> wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl...
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.


Nov 21 '05 #2
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" <fr*****@insightbb.com> wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl...
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.


Nov 21 '05 #3
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" <fr*****@insightbb.com>
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.


Nov 21 '05 #4
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" <fr*****@insightbb.com>
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.


Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Bil Muh | last post by:
Esteemede Developers, I would like to Thank All of You in advance for your sincere guidances. I am developing a software using Visual C++ .NET Standard Edition with Windows Form (.NET)...
3
by: Diego TERCERO | last post by:
Hi... I'm working on a tool for editing text resources for a family of software product my company produces. These text resources are found in a SQL Server database, in a table called...
0
by: Angel | last post by:
How can I search a datagrid's rows (for a string) and then display only the rows where the item was found? The datagrid's already filled but I don't know where or how if filled up. Thanks.
3
by: vinayak | last post by:
Hi I am displaying data in Datagrid in ASP.NET with Edit/Update functionality for each row. On the same page I have 2 Button controls which submits the request to server. These button controls...
4
by: Tim T | last post by:
Hi, I have a stored procedure executing a search and an asp.net page displaying the results in a datagrid. The datagrid has paging on it, I am using Visual Studio.NET and can't see any option...
2
by: Mervin Williams | last post by:
I just discovered that the datagrid does not display if the webform is in new mode. Let's say, for instance, that my datagrid is for contacts related to a company, so that companyid id a foreign...
5
by: quanga | last post by:
Hi- I have a datagrid that in some cases can be several thousand rows in length. What I'd like it to do is have the data pushed to the browser after every, say, 100 rows or so. Kind of a...
3
by: Gerhard | last post by:
I would like a DataGrid I am using to show a default number of rows (10) with the heading, even if the dataset it is bound to returns less than that number of rows (0-9). It is a databound grid...
0
by: latin & geek via DotNetMonster.com | last post by:
hi! ok, im working on a database application. ive successfully managed to establish a relationship between two tables and display them on a datagrid, edit and add new records to them. now i...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.