Hi I'm new to programming but have learned pretty fast and have most of my small application figured out. But the part that I'm working on now has got me.
I have a form with some text boxes that after they are filled out get added as a new row to my datagridview.
But some of the textboxes are joined together such as boxes for First, Middle, and Last name, which are added to one cell in the format of Last, First Middle, because the .csv that will be exported is used for dataset variables in Photoshop and there is one single text line for the full name.
I have some code using the stringsplit, and it actually works, except it always loads the cell data from the first row, even when I click on a different row and it adds the data that isnt using the stringsplit.
Heres part of the code:

Dim i As Integer
Dim line As String = DataGridView1.Item(1, i).Value
Dim separators() As String = {",", " "}
Dim name() As String

i = DataGridView1.CurrentRow.Index
name = line.Split(separators, StringSplitOptions.RemoveEmptyEntries)

txtOrder.Text = DataGridView1.Item(0, i).Value
txtFirst.Text = name(1)
txtMiddle.Text = name(2)
txtLast.Text = name(0)
txtAddress.Text = DataGridView1.Item(2, i).Value

So say I have two rows in my datagridview, each represent a different order with different data. When I click on the second row, it loads the correct values for the txtOrder.text and txtAddress.text, but it loads the first, middle, and last names from the FIRST row to the three text boxes (albeit it correctly splits string and adds it correctly to the textboxes).

I hope I explained the problem enough, this is my first post ever asking about programming lol.
Hopefully someone can help me out!
Thanks
Taylor

I was able to figure out what was wrong. Simple mistake lol. Needed to move "i=datagridview1.currentrow.index" to right below "Dim i as integer".

Dim i As Integer
i = DataGridView1.CurrentRow.Index

Dim line As String = DataGridView1.Item(1, i).Value
Dim separators() As String = {",", " "}
Dim name() As String

name = line.Split(separators, StringSplitOptions.RemoveEmptyEntries)

txtOrder.Text = DataGridView1.Item(0, i).Value
txtFirst.Text = name(1)
txtMiddle.Text = name(2)
txtLast.Text = name(0)
txtAddress.Text = DataGridView1.Item(2, i).Value
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.