multiline textbox to datagridview
Hey there,
I have a multiline textbox with this appearence:
and i want to populate my datagridview to something like this:
i mean, i want to split when there's a "#" , but i don't want multiline cells in datagridview.
i tried this code:
Code:
Dim sup() As String = TextBox1.Text.Split(vbCr, vbLf, vbTab, " "c, "#")
DataGridView1.Rows.Add(sup(0), sup(1), sup(2),sup(3)
but it says it goes outta bounds.. thanks!
Re: multiline textbox to datagridview
Try this.
VB.NET Code:
Dim sup() As String = TextBox1.Text.Replace(vbCr & vbLf, String.Empty).Split(New String() {"#"}, StringSplitOptions.RemoveEmptyEntries)
DataGridView1.Rows.Add(sup(0), sup(1), sup(2), sup(3))
- kgc
Re: multiline textbox to datagridview
Quote:
Originally Posted by
KGComputers
Try this.
VB.NET Code:
Dim sup() As String = TextBox1.Text.Replace(vbCr & vbLf, String.Empty).Split(New String() {"#"}, StringSplitOptions.RemoveEmptyEntries)
DataGridView1.Rows.Add(sup(0), sup(1), sup(2), sup(3))
- kgc
I'd tend to use vbCrLf or, even better, ControlChars.CrLf or, better still, Environment.NewLine rather than 'vbCr & vbLf'. You could also use:
Code:
String.Concat(TextBox1.Lines)
Re: multiline textbox to datagridview
"Index out of Range Exception", i get the same error even knowing i have 4 columns.
http://stackoverflow.com/questions/3...o-datagridview
Re: multiline textbox to datagridview
Quote:
Originally Posted by
iDio
What is the index and what is the range?
Re: multiline textbox to datagridview
i mentioned that in the question.
Re: multiline textbox to datagridview
Quote:
Originally Posted by
iDio
i mentioned that in the question.
Um, no you didn't. You hadn't seen that exception at that time so how could you have? I'm asking you what the index was that was out of range and what the valid range was when the exception was thrown. It's your code and it's running right in front of you. You can see what those values are when it happens. You can also see where the index came from and therefore determine why it's not within the valid range. This is what debugging is. Debugging is not simply reading your code and hoping to see what's wrong with it. It's watching it in action.