ive posted this messge in 3 other forums, i hope i get a better response here.
the following code has a button that removes the selected row from the grid. reset index, is what i am going to use so that the first column is always secquential, so all rows after the deleted one moves up one row.

Private Sub cmdDeleteMSFlexGridRows_Click()
MSFlexGrid1.RemoveItem (MSFlexGrid1.RowSel)
Call resetIndex
End Sub

Private Sub resetIndex()
vIndex = 0
Do While Not msflexgrid1.?????
MSFlexGrid1(vIndex + 1, 0) = vIndex + 1
vIndex = vIndex + 1
Next Row
Loop

End Sub

i dont know what to use at the ???? to say something similar to End Of File.
any ideas to what to put there for this to work?

When you use the RemoveItem command it adjusts the total rows (MSFlexGrid1.Rows) so you may want to just use the good ole for/next loop that uses MSFlexGrid1.Rows as it's max value. Actually, you would want to use MSFlexGrid1.Rows -1 since the total number of rows is one more than what can be referenced since it starts at Zero (total rows of 10 allows for a maximum reference of 9).

i tried

For MSFlexGrid1.Row = 1 To MSFlexGrid1.Row = vIndex
MSFlexGrid1(vIndex + 1, 0) = vIndex + 1
vIndex = vIndex + 1
Next Row
loop

but it doesnt work, is there something im missing? it says theres a problem witth .row

variable required - cant assign to this expression

I don't think you need the vIndex variable if your intent is to number the resulting rows in sequence.

For R = 1 To MSFlexGrid1.Rows - 1
MSFlexGrid1.TextMatrix(R, 0) = R
Next R

If your intent is different, let me know.

I don't think you need the vIndex variable if your intent is to number the resulting rows in sequence.

For R = 1 To MSFlexGrid1.Rows - 1
MSFlexGrid1.TextMatrix(R, 0) = R
Next R

If your intent is different, let me know.

thanks, i didnt know it could work like that. so it works. but it gets stuck at the end when there are no more rows. subscript out of range.

make sure you are doing MSFlexGrid1.Rows -1. You need to subtract one from the total number of rows as it starts with row 0 not 1. So if you have 10 rows, your loop should only go to 9. I just ran the code and it works fine. Here it is and it's poorly written but should demonstrate the point:

Private Sub Command1_Click()
MSFlexGrid1.RemoveItem (2)
For R = 1 To MSFlexGrid1.Rows - 1
MSFlexGrid1.TextMatrix(R, 0) = R
Next R

End Sub

Private Sub Form_Load()
MSFlexGrid1.Cols = 5
MSFlexGrid1.Rows = 10
For R = 1 To MSFlexGrid1.Rows - 1
MSFlexGrid1.TextMatrix(R, 0) = R
Next R

i see. i found why it was doing that error now. it was this line.

For r = 1 To MSFlexGrid1.Rows - 1

i initially had the line

For r = 1 To MSFlexGrid1 - 1

so adding the .rows got rid of the error.

thanks for your help

What Dose the Code Look like for the Button that Deletes the entire row?

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.