By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,825 Members | 1,708 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,825 IT Pros & Developers. It's quick & easy.

Help make the DataGrid my friend...

P: n/a
Most of the Apps I write are 'Data Mining' apps. In VB6, I used the
MSFlexGrid a lot. Now i'm trying to understand the use of the DataGrid,
DataTable, & DataSet.

Using examples I've gotten from here and from other web sites, I've been
able to populate a DataGrid with a CSV file (though I can't say I fully
understand the code used to do it). Like, where do I find references to all
that gibberish in the ConnectionString?
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dirImport & ";Extended
Properties=""Text;HDR=No;"""

I'm wondering if there are any tutorials, or detailed explanations of the
DataGrid, DataTable, & DataSet. MSDN says "heres what this does, and here's
some code to do this." Well, that's not what I want to do.

Scenario 1: I need to load a CSV file into a datagrid, modify the data (this
includes deleting & adding columns), and write the data in the grid back to
a file (not necessarily the source file). I would like the user to be able
to select a particular column, hit the delete button, and see the column
disappear.

Scenario 2: Create a DataTable/DataSet in memory, bind it to the DataGrid,
modify the data (again, including deleting & adding columns), then write the
data out to a file. Sometimes I'll need to use the live data from the Grid
to perform functions (like pinging a list of computers in the Grid, and then
adding a column with the IP addresses of those computers to the Grid).

I'm a complete newbie to the dotnet arena so any help & direction is
gratefully accepted.
Nov 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Cor
Hi Terry,

Here a sample a little bit changed on what I thought you told.
(The CSV has to be in the correct way as in the global settings)

\\\
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim file As String = "Test2.txt"
Dim path As String = "C:\"
Dim ds As New DataSet
Try
Dim f As System.IO.File
If f.Exists(path & file) Then
Dim ConStr As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
path & ";Extended Properties=""Text;HDR=No;FMT=Delimited\"""
Dim conn As New OleDb.OleDbConnection(ConStr)
Dim da As New OleDb.OleDbDataAdapter("Select * from " & _
file, conn)
da.Fill(ds, "TextFile")
End If
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
DataGrid1.DataSource = ds.Tables(0)
End Sub

Try somethings with the datagrid first and ask again

To write it as an XML file. If you want a CSV you should use a loop and
write row by row as far as I know. (However using the datatable in the
dataset not the grid)

Private Sub An event you want ot use let say a write button
DirectCast(BindingContext(ds.Tables(0)),
CurrencyManager).EndCurrentEdit()
ds.WriteXML("C:\Test.XML")
End Sub

I hope this helps?

Cor
Nov 20 '05 #2

P: n/a
Cor
Hi Terry,

Here a sample a little bit changed on what I thought you told.
(The CSV has to be in the correct way as in the global settings)

\\\
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim file As String = "Test2.txt"
Dim path As String = "C:\"
Dim ds As New DataSet
Try
Dim f As System.IO.File
If f.Exists(path & file) Then
Dim ConStr As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
path & ";Extended Properties=""Text;HDR=No;FMT=Delimited\"""
Dim conn As New OleDb.OleDbConnection(ConStr)
Dim da As New OleDb.OleDbDataAdapter("Select * from " & _
file, conn)
da.Fill(ds, "TextFile")
End If
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
DataGrid1.DataSource = ds.Tables(0)
End Sub

Try somethings with the datagrid first and ask again

To write it as an XML file. If you want a CSV you should use a loop and
write row by row as far as I know. (However using the datatable in the
dataset not the grid)

Private Sub An event you want ot use let say a write button
DirectCast(BindingContext(ds.Tables(0)),
CurrencyManager).EndCurrentEdit()
ds.WriteXML("C:\Test.XML")
End Sub

I hope this helps?

Cor
Nov 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.