|
Hoi Friends,
how can i add datas from a csv to a (columned) Listbox ?
The .csv-file has the following format (multiple rows): Sonntag, 18. Oktober 2009;214782;9,99;10;EUro;7,76;100;1,29
Doei from the netherlands Franz | | Trixi-N Sunday, October 18, 2009 1:34 PM | OK...I'm not sure why it's rounding the decimals ??? I didn't have a lot of time yesterday to play with it. Up until your question I had never used the ChartControl, so I'm not real familiar with it
I don't know from the csv file what the values represent, except the first. so you can change the Column names to something a little more descriptive :)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ofd As New OpenFileDialog
If ofd.ShowDialog = Windows.Forms.DialogResult.OK AndAlso ofd.FileName <> "" Then
Try
Using reader As New Microsoft.VisualBasic.FileIO.TextFieldParser(ofd.FileName)
reader.TextFieldType = FileIO.FieldType.Delimited
reader.SetDelimiters(";")
While Not reader.EndOfData
Dim Fields() As String = reader.ReadFields
Dim item As New ListViewItem
item.Text = Fields(0)
For x = 1 To UBound(Fields)
item.SubItems.Add(Fields(x))
Next
ListView1.Items.Add(item)
End While
End Using
Catch ex As Exception
MessageBox.Show(Err.Description)
End Try
End If
ListView1.AutoResizeColumn(0, ColumnHeaderAutoResizeStyle.ColumnContent)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ListView1.Columns.Add("_Date")
ListView1.Columns.Add("Value1")
ListView1.Columns.Add("Value2")
ListView1.Columns.Add("Value3")
ListView1.Columns.Add("Value4")
ListView1.Columns.Add("Value5")
ListView1.Columns.Add("Value6")
ListView1.Columns.Add("Value7")
ListView1.View = View.Details
End Sub
End Class
- Marked As Answer byTrixi-N Sunday, October 18, 2009 3:07 PM
-
| | jwavila Sunday, October 18, 2009 1:59 PM | Hi Trixi
I'm still working on displaying the decimals properly in the chart. Hopefully I'll have an answer shortly
as far as this question
first I would use a DataGridView or a ListView, both of which support multiple columns better than a ListBox
which do you want to use?
then you can use the code I showed in your other post using the TextFieldParser, and set the Delimiter to the ; | | jwavila Sunday, October 18, 2009 1:40 PM | Hoi,
its not important what i habe to use - it must work ;-) So i can use a Listview, no problem.
With the other prob with the decimals its also not important to draw the bars "in decimal" only the value showd above should contain the decimals.
Doei Franz | | Trixi-N Sunday, October 18, 2009 1:42 PM | OK...I'm not sure why it's rounding the decimals ??? I didn't have a lot of time yesterday to play with it. Up until your question I had never used the ChartControl, so I'm not real familiar with it
I don't know from the csv file what the values represent, except the first. so you can change the Column names to something a little more descriptive :)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ofd As New OpenFileDialog
If ofd.ShowDialog = Windows.Forms.DialogResult.OK AndAlso ofd.FileName <> "" Then
Try
Using reader As New Microsoft.VisualBasic.FileIO.TextFieldParser(ofd.FileName)
reader.TextFieldType = FileIO.FieldType.Delimited
reader.SetDelimiters(";")
While Not reader.EndOfData
Dim Fields() As String = reader.ReadFields
Dim item As New ListViewItem
item.Text = Fields(0)
For x = 1 To UBound(Fields)
item.SubItems.Add(Fields(x))
Next
ListView1.Items.Add(item)
End While
End Using
Catch ex As Exception
MessageBox.Show(Err.Description)
End Try
End If
ListView1.AutoResizeColumn(0, ColumnHeaderAutoResizeStyle.ColumnContent)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ListView1.Columns.Add("_Date")
ListView1.Columns.Add("Value1")
ListView1.Columns.Add("Value2")
ListView1.Columns.Add("Value3")
ListView1.Columns.Add("Value4")
ListView1.Columns.Add("Value5")
ListView1.Columns.Add("Value6")
ListView1.Columns.Add("Value7")
ListView1.View = View.Details
End Sub
End Class
- Marked As Answer byTrixi-N Sunday, October 18, 2009 3:07 PM
-
| | jwavila Sunday, October 18, 2009 1:59 PM | Hoi,
thx a lot (Dank u wel ) - this works really fine.
Doei Franz
| | Trixi-N Sunday, October 18, 2009 2:44 PM | Good, glad it works...
please mark this thread as answered to close it.
This also helps others find an answer to their problem - Marked As Answer byTrixi-N Sunday, October 18, 2009 2:59 PM
- Unmarked As Answer byTrixi-N Sunday, October 18, 2009 3:08 PM
-
| | jwavila Sunday, October 18, 2009 2:58 PM |
|