Results 1 to 14 of 14

Thread: SelectedIndexChanged RESOLVED

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    11

    Question SelectedIndexChanged RESOLVED

    Hi

    I have a function "Private Sub fillBoxes(ByVal recordPos As Integer)" which fills several text boxes in the page with the contents of a database table row. RecordPos is the number of the row in the table.

    I can call this function in the pageload with fillBoxes(0), or fillBoxes(4) or whatever and it works fine. However, I am trying to call it from the SelectedIndexChanged event of a DropDownList, like this:

    Private Sub ddlKey_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ddlKey.SelectedIndexChanged
    fillBoxes(ddlKey.SelectedIndex)
    End Sub

    So basically the user selects a value from the list and the textboxes are filled with the corresponding data row. This throws an exception, however, saying "There is no row at position X". There is nothing wrong with the function as it works fine when I call it in the page load.

    Any ideas what could be wrong?

    Thanks
    Joe
    Last edited by joef; May 17th, 2005 at 08:18 AM.

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: SelectedIndexChanged

    Set a breakpoint on that line of code. What value does SelectedIndex hold?

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    11

    Re: SelectedIndexChanged

    Thanks for the reply. I set the breakpoint, and selected the fourth item on from the DropDownList. Since it is zero-based, the value of SelectedIndex should be 3, and it is. Since there are 30-odd records in the database table, 3 should be fine, in theory...?

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: SelectedIndexChanged

    Yes it should. Now go F11, into the function you made. Try following it until you get to the dataset's call based upon that index.

    Try setting a quickwatch on the dataset too.

  5. #5

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    11

    Re: SelectedIndexChanged

    Ok now this is weird. The function looks like this:

    Private Sub fillBoxes(ByVal recordPos As Integer)
    txtDesc.Text = DsAll1.HDSLMT(recordPos).DESCRIPTION

    txtChoice1.Text = DsAll1.HDSLMT(recordPos).VALCHAR_1
    txtChoice2.Text = DsAll1.HDSLMT(recordPos).VALCHAR_2
    etc...
    ...
    txtChoice9.Text = DsAll1.HDSLMT(recordPos).VALCHAR_9

    txtDesc1.Text = DsAll1.HDSLMT(recordPos).VALTXT_1
    txtDesc2.Text = DsAll1.HDSLMT(recordPos).VALTXT_2
    etc...
    ...
    txtDesc9.Text = DsAll1.HDSLMT(recordPos).VALTXT_9
    End Sub

    But none of those lines actually throw the exception. The exception is thrown at line 406, which is in a button click event handler, and that button hasn't even been clicked?!

    I'm not a very experienced programmer and maybe I'm talking rubbish but to me that doesn't make sense.

  6. #6
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: SelectedIndexChanged

    And you used F11 to break in?

  7. #7

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    11

    Re: SelectedIndexChanged

    In my understanding F11 is just a shortcut for start program.

  8. #8
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: SelectedIndexChanged

    Um... no, when you reach the line which calls the function you wrote, F11 will break into that function so you can follow the values being passed.

  9. #9

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    11

    Re: SelectedIndexChanged

    I feel like I'm being really stupid here and just wasting your time. Sorry. This is a web application. I definitely should have said that at the start. All F11 does is alter the size of the browser window.

  10. #10
    Addicted Member
    Join Date
    Jan 2005
    Posts
    136

    Re: SelectedIndexChanged

    by the way F8 will break into that function in my PC. so my advice is to double check

  11. #11

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    11

    Re: SelectedIndexChanged

    Ahh, it's all clicked now

    I'll see what I can find by this method.

  12. #12

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    11

    Re: SelectedIndexChanged

    Yep, I've fixed the problem now. Thanks a lot guys.

  13. #13
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: SelectedIndexChanged

    Add [Resolved] to the thread title. And perhaps tell us what the problem was.

  14. #14

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    11

    Re: SelectedIndexChanged RESOLVED

    Ok, have done.

    The problem was that immediately before calling the function, I needed to refill the dataset with the dataadapter. Otherwise, for some still unknown reason, it lost its records when the SelectedIndexChanged event occured.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width