473,406 Members | 2,956 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Help make the DataGrid my friend...

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
2 1644
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Gidi | last post by:
Hi, I have DataGrid and i want to use the arrows to navigate up and down between the lines. i also want that each row i'm in, will be marked (as in DataGrid.Select(row_number)). When my form is...
7
by: Juan Romero | last post by:
Hey guys, please HELP I am going nuts with the datagrid control. I cannot get the damn control to refresh. I am using soap to get information from a web service. I have an XML writer output...
0
by: DC Gringo | last post by:
I am trying to output simply DataGrid of a coutry listing on a web form via a business object and XML web service...I receive no errors but no table HTML either. (I know the service and business...
0
by: DC Gringo | last post by:
I am trying to output simply DataGrid of a coutry listing on a web form via a business object and XML web service...I receive no errors but no table HTML either. (I know the service and business...
0
by: Terry Olsen | last post by:
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...
7
by: Aaron | last post by:
Complete code follows. I am new to .NET programming (and programming in general) and I am having a difficult time understanding how to fill a variable in one sub, and then access it from...
3
by: Adriano | last post by:
Hello, when I try to print something, either DataGrid or from Crystal Report viever the folowing error message appears and cancels printing: Object reference not set to an instance of an...
0
by: excelleinc.com | last post by:
Hello, I know that this question was here quite a few times but I was wondering if anyone atually found a solution/work around for it. I'm trying to prevent users from deleting certain rows in...
11
by: CM Manager via DotNetMonster.com | last post by:
I am very frustrated due to this exception error I am receiving. I've tried searching numerous user support groups, Microsoft Support Net, Google, etc. and haven't found exactly my situation....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.