-
Apr 5th, 2016, 10:21 AM
#1
Thread Starter
Member
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!
-
Apr 5th, 2016, 01:05 PM
#2
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
-
Apr 5th, 2016, 09:08 PM
#3
Re: multiline textbox to datagridview
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)
-
Apr 6th, 2016, 03:26 AM
#4
Thread Starter
Member
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
Last edited by iDio; Apr 6th, 2016 at 03:36 AM.
-
Apr 6th, 2016, 05:38 AM
#5
Re: multiline textbox to datagridview
Originally Posted by iDio
What is the index and what is the range?
-
Apr 7th, 2016, 07:33 AM
#6
Thread Starter
Member
Re: multiline textbox to datagridview
i mentioned that in the question.
-
Apr 7th, 2016, 07:02 PM
#7
Re: multiline textbox to datagridview
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.
Tags for this Thread
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
|