selectedRowIndex issue

Hi all.

This probably is simple, but I can’t get it to work.

When I select a row in a listbox, I want to check a checkbox in a column. However when I run this code, I get an out of bounds error.

window1.ListBox1.CellCheckBoxStateAt(window1.ListBox1.SelectedRowIndex,5) = DesktopCheckbox.VisualStates.Checked

I know I am getting the correct row index, as I show it in a messagebox.

Can anyone see my error?

Regards

Can you build it into a sample project some more? Where this code occurs could be important. If there’s no selection, SelectedRowIndex is -1 and that could be causing a problem with CellCheckboxStateAt

1 Like

Remember that columns are zero-based. Are you sure that it’s column 5 and not column 4?

When the code is stopped with the out-of-bounds error, examine the values of all properties/variables used as indices. The problem will usually be obvious.

2 Likes

Hi Julia. I looked at all of the variables and do indeed see a -1 which makes sense for an out of bounds error.

But when I run my code, my selectedrowindex is what I expect it to be.

So I’m going to post my code, which TimParnell asked for.

Here is the code if you are interested.


var i as Integer
var newUpdatingNewDay as New DateInterval

newUpdatingNewDay.Days = 7

// ok.  Let's do this again...and SAVE IT, moron.
// so we will need to see the row index selected.

app.whatWAStheSelectedIndex = window1.ListBox1.SelectedRowIndex

//for testing only
MessageBox "The selected Row index is : " + app.whatWAStheSelectedIndex.ToString
MessageBox "The number of rows in the run is: "+ window1.ListBox1.RowCount.ToString

//so now let's remove the rows from the selected Row Index to the end of the available rows.
for i = (window1.ListBox1.RowCount - 1) to (app.whatWAStheSelectedIndex) step -1
  Window1.ListBox1.RemoveRowAt(i)
next i


//now let's take the value that is in the listbox column 4 and make it our new currentdateandtime
app.theCurrentDateAndTime = DateTime.FromString (window1.ListBox1.CellTextAt(i, 4))

//test checkbox
window1.ListBox1.CellCheckBoxStateAt(window1.ListBox1.SelectedRowIndex,5) = DesktopCheckbox.VisualStates.Checked
//for testing only
MessageBox "The new value of current date time is : "+app.theCurrentDateAndTime.ToString

//move the focus back to the principal textfield
window1.TextField1.SetFocus

// window1.TextField1.text = window1.ListBox1.celltextAt(i,0)

//the other entries ( rate and payment are still filled in so we don't have to do anything with that.
// now just run the calculations again, starting at the lastRowIndex.
// note: if they select rowIndex1 they should just start another run.  

app.theCurrentDateAndTime = app.theCurrentDateAndTime + newUpdatingNewDay

// for testing only
MessageBox "The updated next date is : "+app.theCurrentDateAndTime.ToString

// clear out the fields in window1
window1.TextField1.text = ""
window1.TextField2.text = ""
window1.TextField3.text = ""

// open the window so they can enter what they want / need the new values to be
window2.show

Here’s the code Tim.

I do get the -1, so that makes sense, but when I run the code the messagebox that I use for testing purposes shows a ‘real’ value, not -1.

Per your request, here is the code:


var i as Integer
var newUpdatingNewDay as New DateInterval

newUpdatingNewDay.Days = 7

// ok.  Let's do this again...and SAVE IT, moron.
// so we will need to see the row index selected.

app.whatWAStheSelectedIndex = window1.ListBox1.SelectedRowIndex

//for testing only
MessageBox "The selected Row index is : " + app.whatWAStheSelectedIndex.ToString
MessageBox "The number of rows in the run is: "+ window1.ListBox1.RowCount.ToString

//so now let's remove the rows from the selected Row Index to the end of the available rows.
for i = (window1.ListBox1.RowCount - 1) to (app.whatWAStheSelectedIndex) step -1
  Window1.ListBox1.RemoveRowAt(i)
next i


//now let's take the value that is in the listbox column 4 and make it our new currentdateandtime
app.theCurrentDateAndTime = DateTime.FromString (window1.ListBox1.CellTextAt(i, 4))

//test checkbox
window1.ListBox1.CellCheckBoxStateAt(window1.ListBox1.SelectedRowIndex,5) = DesktopCheckbox.VisualStates.Checked
//for testing only
MessageBox "The new value of current date time is : "+app.theCurrentDateAndTime.ToString

//move the focus back to the principal textfield
window1.TextField1.SetFocus

// window1.TextField1.text = window1.ListBox1.celltextAt(i,0)

//the other entries ( rate and payment are still filled in so we don't have to do anything with that.
// now just run the calculations again, starting at the lastRowIndex.
// note: if they select rowIndex1 they should just start another run.  

app.theCurrentDateAndTime = app.theCurrentDateAndTime + newUpdatingNewDay

// for testing only
MessageBox "The updated next date is : "+app.theCurrentDateAndTime.ToString

// clear out the fields in window1
window1.TextField1.text = ""
window1.TextField2.text = ""
window1.TextField3.text = ""

// open the window so they can enter what they want / need the new values to be
window2.show

The problem is you are deleting the row that was selected, thus deselecting it.

Try

for i = (window1.ListBox1.RowCount - 1) to (app.whatWAStheSelectedIndex + 1) step -1
  Window1.ListBox1.RemoveRowAt(i)
next i
1 Like

Thanks Paul.

I just found that, like two minutes ago. But thank you and everyone for their time and assistance!
Thanks Tim(s), Julia and all.

Regards

1 Like