Rows in Datagrid

T

tshad

I have a couple of problems with my datagrid in vb.net.

In asp.net I can do the following to loop through a datagrid.

for each oItem as DataGridItem in DataGrid1.Items

This apparently doesn't work in vb.net. How would I do it there?

Also, I am trying put bind my DataTable from my Dataset to my DataGrid. I
have 37 rows in the table but after binding it to the Datagrid, it shows the
column titles correctly but no data and only one row.

DataGrid1.DataSource = DataSetObj
DataGrid1.DataMember = "DTGLConversion"

Is there something else I need to do to move the data to the DataGrid?
There is no DataBind method as there is in asp.net.

If I do:

Dim temp As Integer = DataGrid1.VisibleRowCount

I get temp = 3

I really wish they had the same methods and properties for the Datagid in
both asp.net and vb.net.

Thanks,

Tom
 
G

Guest

The datasource s/b the table object. So try this

DataGrid1.DataSource = DataSetObj.DTGLConversion
DataGrid1.DataMember = ""
 
L

Lloyd Sheen

tshad said:
I have a couple of problems with my datagrid in vb.net.

In asp.net I can do the following to loop through a datagrid.

for each oItem as DataGridItem in DataGrid1.Items

This apparently doesn't work in vb.net. How would I do it there?

Also, I am trying put bind my DataTable from my Dataset to my DataGrid. I
have 37 rows in the table but after binding it to the Datagrid, it shows
the column titles correctly but no data and only one row.

DataGrid1.DataSource = DataSetObj
DataGrid1.DataMember = "DTGLConversion"

Is there something else I need to do to move the data to the DataGrid?
There is no DataBind method as there is in asp.net.

If I do:

Dim temp As Integer = DataGrid1.VisibleRowCount

I get temp = 3

I really wish they had the same methods and properties for the Datagid in
both asp.net and vb.net.

Thanks,

Tom


I think you should be binding the datatable found in the dataset.

Hope this helps
LS
 
T

tshad

Terry said:
The datasource s/b the table object. So try this

DataGrid1.DataSource = DataSetObj.DTGLConversion
DataGrid1.DataMember = ""

Nope.

That didn't work.

It wouldn't even allow me to do it.

I also tried, based on your suggestion:

DataSetObj.Tables("DTGLConversion")

But the same thing happened - showed the columns with no data. It I clicked
on one of the cells all the cells then had [null] in them.

Thanks,

Tom
 
T

tshad

Lloyd Sheen said:
I think you should be binding the datatable found in the dataset.

How do I do that?

If I just do:

DataSetObj.Tables("Table"), for some reason it puts all kinds of data in it.
I assume it grabs the data from all the tables in the Data Set.

Thanks,

Tom
 
T

Tom Shelton

How do I do that?

If I just do:

DataSetObj.Tables("Table"), for some reason it puts all kinds of data in it.
I assume it grabs the data from all the tables in the Data Set.

Thanks,

Tom






- Show quoted text -- Hide quoted text -

- Show quoted text -

Dim ds As New DataSet("TestData")

Dim table As DataTable = ds.Tables.Add("Test1")
table.Columns.Add("Column1", GetType(Integer))
table.Columns.Add("Column2", GetType(String))
table.Columns.Add("Column3", GetType(Boolean))

table.Rows.Add(1, "Jim", False)
table.Rows.Add(2, "Sue", True)
table.Rows.Add(3, "Bob", True)
table.Rows.Add(4, "Ed", False)

table.AcceptChanges()

Me.DataGridView1.DataSource = ds.Tables("Test1")

I put this in my form_load. Works fine. Are you using the old
deprecated datagrid or the new datagridview?
 
T

tshad

tshad said:
Terry said:
The datasource s/b the table object. So try this

DataGrid1.DataSource = DataSetObj.DTGLConversion
DataGrid1.DataMember = ""

Nope.

That didn't work.

It wouldn't even allow me to do it.

I also tried, based on your suggestion:

DataSetObj.Tables("DTGLConversion")

But the same thing happened - showed the columns with no data. It I
clicked on one of the cells all the cells then had [null] in them.

I also tried:

DataGrid1.DataSource = DTGLConversion

Which was the Table I added to the Data Set and that didn't work either.

It obviously can read the table as it has the Headings correct. When I look
at the debugger it sees the columns correctly and when I look at it as:

DTGLConversion.Row(1).Item(2) - it sees it fine.

If I do it int the Watch table as:

DataSetObj.Tables("DTGLConversion").Rows(2).item(1)

I get:

"1084" {String} Object

Which I expect. But the DataGrid doesn't show it.

Thanks,

Tom
 
T

tshad

I also tried:

DataGrid1.SetDataBinding(DataSetObj, "DTGLConversion")

Same result.

Not sure what the problem is.

It is so much easier in asp.net. Not sure why it is different in vb.net.

Thanks,

Tom

tshad said:
tshad said:
Terry said:
The datasource s/b the table object. So try this

DataGrid1.DataSource = DataSetObj.DTGLConversion
DataGrid1.DataMember = ""

Nope.

That didn't work.

It wouldn't even allow me to do it.

I also tried, based on your suggestion:

DataSetObj.Tables("DTGLConversion")

But the same thing happened - showed the columns with no data. It I
clicked on one of the cells all the cells then had [null] in them.

I also tried:

DataGrid1.DataSource = DTGLConversion

Which was the Table I added to the Data Set and that didn't work either.

It obviously can read the table as it has the Headings correct. When I
look at the debugger it sees the columns correctly and when I look at it
as:

DTGLConversion.Row(1).Item(2) - it sees it fine.

If I do it int the Watch table as:

DataSetObj.Tables("DTGLConversion").Rows(2).item(1)

I get:

"1084" {String} Object

Which I expect. But the DataGrid doesn't show it.

Thanks,

Tom
Thanks,

Tom
 
T

tshad

Tom Shelton said:
Dim ds As New DataSet("TestData")

Dim table As DataTable = ds.Tables.Add("Test1")
table.Columns.Add("Column1", GetType(Integer))
table.Columns.Add("Column2", GetType(String))
table.Columns.Add("Column3", GetType(Boolean))

table.Rows.Add(1, "Jim", False)
table.Rows.Add(2, "Sue", True)
table.Rows.Add(3, "Bob", True)
table.Rows.Add(4, "Ed", False)

table.AcceptChanges()

Me.DataGridView1.DataSource = ds.Tables("Test1")

I put this in my form_load. Works fine. Are you using the old
deprecated datagrid or the new datagridview?\

I am running on VS 2003 and using the DataGrid from the ToolBox - so I
assume this won't work on my program.

Thanks,

Tom
 
T

tshad

I figured out what was happening, just not why.

I am doing the following:

DataGrid1.DataSource = DataSetObj.Tables(2)

And than later in the code I am clearing the Table (not the DataGrid).

DTGLConversion.Rows.Clear()

This is during the same Button event.

I assume that either the Table is always looking at the table and there is
nothing really in the DataTable or it doesn't bind the DataTable until the
end.

If it is the Binding issue, is there some way to tell it to bind before I do
the DTGLConversion.Rows.Clear()?

Thanks,

Tom
tshad said:
Tom Shelton said:
Dim ds As New DataSet("TestData")

Dim table As DataTable = ds.Tables.Add("Test1")
table.Columns.Add("Column1", GetType(Integer))
table.Columns.Add("Column2", GetType(String))
table.Columns.Add("Column3", GetType(Boolean))

table.Rows.Add(1, "Jim", False)
table.Rows.Add(2, "Sue", True)
table.Rows.Add(3, "Bob", True)
table.Rows.Add(4, "Ed", False)

table.AcceptChanges()

Me.DataGridView1.DataSource = ds.Tables("Test1")

I put this in my form_load. Works fine. Are you using the old
deprecated datagrid or the new datagridview?\

I am running on VS 2003 and using the DataGrid from the ToolBox - so I
assume this won't work on my program.

Thanks,

Tom
 
T

Tom Shelton

I am running on VS 2003 and using the DataGrid from the ToolBox - so I
assume this won't work on my program.

Thanks,

Tom


I just replaced the datagridview with the old datagrid

Me.DataGrid1.DataSource = ds.Tables("Test1")

Works fine. Maybe you should show us the structure of your dataset,
maybe the statement used to fill it...
 
T

tshad

Tom Shelton said:
I just replaced the datagridview with the old datagrid

Me.DataGrid1.DataSource = ds.Tables("Test1")

Works fine. Maybe you should show us the structure of your dataset,
maybe the statement used to fill it...

I found the problem and explain it in my last post which probably wasn't
there when you posted this one.

I just don't know why it is doing it.

Thanks,

Tom
 
G

Guest

You may have figured this out by now, but in case not...
It was not clear from your original post, but it looks like what you did was
create a datatable - DTGLConversion, and then added it to your DataSet. So,
at this point you have TWO references to the same DataTable, one through
DTGLConversion and one through DataSetObj.Tables(2). ONE Datatable - 2
references. Now when you set the grids DataSource to this table, you have
THREE references to the same DataTable. Still just one DataTable. And when
you clear the rows using one of the references, the one and only one
datatable's rows are cleared.

--
Terry


tshad said:
Tom Shelton said:
I just replaced the datagridview with the old datagrid

Me.DataGrid1.DataSource = ds.Tables("Test1")

Works fine. Maybe you should show us the structure of your dataset,
maybe the statement used to fill it...

I found the problem and explain it in my last post which probably wasn't
there when you posted this one.

I just don't know why it is doing it.

Thanks,

Tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top