How to display array contents to DataGridView?

nescartel

Member
Joined
Jun 10, 2007
Messages
22
Programming Experience
3-5
hi all,

is it possible to display contents of an array to DataGridView?
a lot of topic i see is about displaying data from database or other types,
so is it possible?

i am trying to continuously display value of array to DataGridView,
and the array is constantly changed,
therefore the DataGridView will always be updated.
if it is possible, can anyone please point me to a tutorial to do so?

thank you very very much! :)
 
You would have to put that data into a data set.

Is there any reason why you have to use a datagridview?

Is this a one dimensional array?

There are tons of other controls that contain a GetRange function which takes pretty much any array as input and will display its contents.
 
hmmm,
what is a dataset anyways?
yes, i am using a 1-dimensional array.
there's no proper reason why i wanted to display it using DataGridView,
just thought that it's nice to have the table-like display.
FYI i am creating a "HEX DATA DISPLAYER", which reads hexadecimal values from EEPROM, store into array, and display it into any nice display; and at this time, all i can think of is the DataGridView. am i going in the right direction here?

thank you in advance! ;)
 
The easiest thing you can do in this scenario to have the control update as you update the source list is to use ListBox control and BindingList(Of String). Declare it like this:
VB.NET:
Private bl As New System.ComponentModel.BindingList(Of String)
Assign the datasource:
VB.NET:
ListBox1.DataSource = bl
Now, when you add new string items to the source they will also display automatically in Listbox:
VB.NET:
bl.Add("new string" & bl.Count)

You can't do this exact thing with DataGridView, because it will reflect a property of the item, for String class the Length property will display and is useless in this context. In this case you would create a class and bind this, more useful if there are more than one property (multicolumn table). You could also use a DataTable then. (Dataset contains datatables and relations.)
 
Back
Top