DataGrid Question

  • Thread starter Thread starter Wayne Taylor
  • Start date Start date
W

Wayne Taylor

I some code which reads in data from a CSV formatted file, I would to
display that data in a datagrid does anyone have any suggestions on how this
could be done, do I have to create a dataset etc....

Thanks in advance

Wayne
 
Wayne Taylor said:
I some code which reads in data from a CSV formatted file, I would to
display that data in a datagrid does anyone have any suggestions on how this
could be done, do I have to create a dataset etc....

2 ways I can think of off top of head:

1) Similar to what you suggest, create a DataTable object, add the columns,
then loop through creating NewRow()s and setting their values.

2) There is an OLE provider that will happily open a CSV file and allow you
to do a "select * " from it, which will result in a dataset. Can't remember
the connection string off top of head, but search google for... hang on...
connectionstrings.com has one ready made:

"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\txtFilesFolder\;Extended
Properties=""text;HDR=Yes;FMT=Delimited"""

HTH

Tobin Harris
 
I some code which reads in data from a CSV formatted file, I would to
display that data in a datagrid does anyone have any suggestions on how this
could be done, do I have to create a dataset etc....

The Windows Forms DataGrid relies on data binding to work with its data. A DataSource for use with DataBinding needs to implement one of IList, ITypedList, or IBindingList. So you can use an ArrayList as a valid source (though you need to use "ArrayList" as the MappingName if you want to adjust the style of the grid presentation, or the type name of your collection if you roll your own typesafe list).
However if you are reading a CSV file, I am guessing that you might have something that lends itself well to representation as a table. In that case you could use a DataTable - which you construct on the fly - to hold your values and use that as the DataSource. If your CSV file has multiple tables, then you can use a DataSet to hold your DataTable collection and use that as the DataSource
Ian Cooper
wwww.dnug.org.uk
 
Back
Top