DataGrif ???????? Help

  • Thread starter Thread starter NEWS
  • Start date Start date
N

NEWS

I want to display data in a VB.NET DataGrid - but the data is from my VB
code, not bound to a database.

I am using code like this :-
DataGrid1.Item(1, 1) = "Test"

I keep getting the message "Data cannot be read from a DataGrid which is not
bound to a DataTable"

What am I doing wrong?

thanks


Garry
 
Garry,
I keep getting the message "Data cannot be read from a DataGrid which is
not
bound to a DataTable"

What am I doing wrong?

You cannot use a datagrid which is not bound to a datasource

Cor
 
Oh! I did not realise that.

Is there another grid that can comes with VB.NET that I can use?
 
You can bind an array list to a datagrid if all the elements of the arraylist
are classes that all have the same properties that you want to display. Note
that some functionality is lost like sorting columns but you can implement
this by intercepting mouse down events on the datagrid columns and sort the
arraylist on the datagrid column by using an Icomparer.
 
Garry,

You can use another grid, however a datatable is very easy to make

All typed here

\\\
dim mydatatable as new datatable
mydatatable.columns.add("One")
mydatatable.columns.add("Two")
mydatatable.rows.add(mydatatable.newrow)
mydatatable.rows(0)(0) = "1"
mydatatable.rows(0).item(1) = "2"
mydatagrid.datasource = mydatatable
///
Now you have a datatatable from one rows wich has in its columns one and two
the items 1 and 2 what will displayed in your datagrid1 when you have used
that on your form.

A column is a description of a column
An item is another name of the reference to the object that by instance a
row holds in that column.

I hope this helps?

Cor
 
Cor

thanks for the code. it works great!

Can you explain to me what you are doing?!! What is a datatable?

thanks

Garry
 
Gary,

Greath to hear that explanation inline

\\\
dim mydatatable as new datatable
'create a new object from the datatable class
mydatatable.columns.add("One")
mydatatable.columns.add("Two")
'add to that two column desctriptions
'in the most simple way, this is are as well object
mydatatable.rows.add(mydatatable.newrow)
'add a row to the table, confirm as described in the columnobjects
mydatatable.rows(0)(0) = "1"
mydatatable.rows(0).item(1) = "2"
'set the itemobjects in that to "1" and "2" I show it in 2 ways because
'item is (mostly everywhere) default
mydatagrid.datasource = mydatatable
'add a reference to the datagrid from where is the datatable
///
And to show what is a datatable have a look here

http://msdn.microsoft.com/library/d...f/html/frlrfsystemdatadatatableclasstopic.asp


(I see now that a link to this page could have prevent me from typing,
however maybe is that short sample I made quicker to understand for you)

I hope this answers this questions too?

Cor
 

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


Back
Top