-
Nov 29th, 2013, 06:55 AM
#1
Thread Starter
Junior Member
Export or save delimited text file by quotation from datagrid.
Hi
I have a text file delimited by quotation, that position in a datagrid which I make some changes but then I need to export it or save it to a folder.
In WF do so without any inconvenience.
Also take advantage of the kindness of experts to see how I can agree to paint a column value of a row.
For example, if column A has in his cell a value of 01 is red, if you have 02 yellow value.
should be stored as follows:
'01 '' Manuel jury ''1967' '44 years'
I use Windows Forms WPF
If File.Exists("D:\m2\test.DAT") Then
File.Delete("D:\m2\test.DAT")
End If
Const Dat As String = ("D:\m2\test.DAT")
Using f As New IO.StreamWriter(Dat, True)
Dim col As String = ""
Dim row As String = ""
Dim i As Integer = 0
For Each r As DataGridViewRow In DataGridView1.Rows
For Each c As DataGridViewColumn In DataGridView1.Columns
row = row & "'" & Convert.ToString(r.Cells(c.HeaderText).Value) & "' "
Next
If i < DataGridView1.Rows.Count - 1 Then row &= Environment.NewLine
Next
f.Write(row)
End Using
Cheers
-
Nov 29th, 2013, 07:12 AM
#2
Re: Export or save delimited text file by quotation from datagrid.
You have posted this thread in a the WPF forum but, if you're using a DataGridView, you're using Windows Forms and not WPF. Which is it?
-
Nov 29th, 2013, 10:06 PM
#3
Thread Starter
Junior Member
Re: Export or save delimited text file by quotation from datagrid.
Hi jmcilhinney,
I am putting an example of how I save a text file delimited by quotation using wf.
Now what I want is to save the text file using the wpf platform, that is why I turn to wpf forum.
Cheers
-
Nov 29th, 2013, 10:10 PM
#4
Re: Export or save delimited text file by quotation from datagrid.
Originally Posted by karlosc
Hi jmcilhinney,
I am putting an example of how I save a text file delimited by quotation using wf.
Now what I want is to save the text file using the wpf platform, that is why I turn to wpf forum.
Cheers
Hmmm... I must have missed where you said that in your first post. Nothing like a clear explanation to clearly explain things. So, to be clear, you are able to save data to a text file from a DataGridView in a Windows Forms application and now you want to know how to do the equivalent from a DataGrid in a WPF application, correct?
-
Nov 29th, 2013, 10:15 PM
#5
Thread Starter
Junior Member
Re: Export or save delimited text file by quotation from datagrid.
-
Nov 29th, 2013, 10:38 PM
#6
Re: Export or save delimited text file by quotation from datagrid.
Ok then, please try providing a clear explanation in future because that was absolutely not clear from your first post. Further to that, the code you posted actually won;t produce the output that you claim you want, so that's more inconsistency. It doesn't take much effort to post clearly and it will avoid this big waste of time where we have to post more than once to discern what you actually want. If we have to keep doing that we will lose interest very quickly and then you won't get the help you need, so it's in your best interest and ours.
One problem you have is that the Items of the DataGrid actually contains the itess from the object assigned to the ItemsSource, e.g. if you bound a DataView then each item is a DataRowView. There isn't an equivalent to the DataGridViewRow that will be the same no matter the type of data. My guess is that you are binding data from a DataTable in both cases. Is that correct? If so then you should be using that in code anyway, not the grid.
-
Nov 30th, 2013, 06:38 AM
#7
Thread Starter
Junior Member
Re: Export or save delimited text file by quotation from datagrid.
hello
Thanks for the observation, and taking that into account.
ok, what I have is a text file, which is separated by single quotes. I load this file into a datagrid, modify a field and then save the modified desire. the same format separated by single quotes.
example:
'09 '' Manuel jury ''1967' '44 years' this is the original file
'09 '' Manuel jury ''1967' '54 years' this is the changed file
here the code as position in the datagrid
Imports System.IO
Imports System.Windows.Forms
Imports System.Collections.ObjectModel
Public Partial Class MainWindow
Inherits Window
Private Property SplitRecords() As ObservableCollection(Of Split)
Get
Return m_SplitRecords
End Get
Set(value As ObservableCollection(Of Split))
m_SplitRecords = value
End Set
End Property
Private m_SplitRecords As ObservableCollection(Of Split)
Public Sub New()
InitializeComponent()
StoreDatacontext()
End Sub
Private Sub StoreDatacontext()
Dim leer As New StreamReader("D:\Archivos de programa\m1\prueba.dat")
Dim texto As String = ""
Dim count As Integer = 11
Dim split As String() = Nothing
SplitRecords = New ObservableCollection(Of Split)
While (Not texto Is Nothing)
texto = leer.ReadLine
If (Not texto Is Nothing) Then
split = texto.Split(New Char() {CChar("'")}, count)
' add Split object to SplitCollection
SplitRecords.Add(New Split() With { _
.Split1 = split(1), _
.Split3 = split(3), _
.Split5 = split(5), _
.Split7 = split(7), _
.Split9 = split(9) _
})
End If
End While
Me.DataContext = SplitRecords
End Sub
Private Class Split
Public Property Split1() As String
Get
Return m_Split1
End Get
Set(value As String)
m_Split1 = value
End Set
End Property
Private m_Split1 As String
Public Property Split3() As String
Get
Return m_Split3
End Get
Set(value As String)
m_Split3 = value
End Set
End Property
Private m_Split3 As String
Public Property Split5() As String
Get
Return m_Split5
End Get
Set(value As String)
m_Split5 = value
End Set
End Property
Private m_Split5 As String
Public Property Split7() As String
Get
Return m_Split7
End Get
Set(value As String)
m_Split7 = value
End Set
End Property
Private m_Split7 As String
Public Property Split9() As String
Get
Return m_Split9
End Get
Set(value As String)
m_Split9 = value
End Set
End Property
Private m_Split9 As String
End Class
End Class
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|