473,403 Members | 2,323 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,403 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 1643
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
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.