Listbox problems

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Karin

    #1

    Listbox problems

    Hi,
    Can anyone explain to me why SelectedIndex is automatically changed to 0
    when I set it to -1?

    This happens when I set SelectedIndex = -1 from the click-eventhandler of a
    button. My ListBox is bound to an ArrayList.

    Thanks! /K


  • Ignacio Machin

    #2
    Re: Listbox problems

    Hi Karin,

    Check your handler for SelectedIndexCh ange , the problem may be there.

    Hope this help,

    --
    Ignacio Machin,
    ignacio.machin AT dot.state.fl.us
    Florida Department Of Transportation

    "Karin" <kl@inxl.se> wrote in message
    news:u3ylTYqSDH A.2852@tk2msftn gp13.phx.gbl...[color=blue]
    > Hi,
    > Can anyone explain to me why SelectedIndex is automatically changed to 0
    > when I set it to -1?
    >
    > This happens when I set SelectedIndex = -1 from the click-eventhandler of[/color]
    a[color=blue]
    > button. My ListBox is bound to an ArrayList.
    >
    > Thanks! /K
    >
    >[/color]


    Comment

    • Karin

      #3
      Re: Listbox problems

      Hi,
      I thought so first too so I made a very simple form with just one listbox
      and a button to try it out without the eventhandler for SelectedIndexCh anged
      but the problem was still there.
      Strange thing is that it works as expected when SelectedIndex = 0 before the
      button is clicked.
      I have found a way to avoid the problem which I don't really like but it
      works...

      private bool blnNew = false;
      private void lb_SelectedInde xChanged(object sender, System.EventArg s e)
      {
      if (lb.SelectedInd ex != -1 )
      {
      if (blnNew)
      lb.ClearSelecte d();
      }
      private void button1_Click(o bject sender, System.EventArg s e)
      {
      blnNew=true;
      lb.ClearSelecte d();
      blnNew=false;
      }

      /K

      "Ignacio Machin" <ignacio.mach in AT dot.state.fl.us > wrote in message
      news:#GLXkYtSDH A.2188@TK2MSFTN GP10.phx.gbl...[color=blue]
      > Hi Karin,
      >
      > Check your handler for SelectedIndexCh ange , the problem may be there.
      >
      > Hope this help,
      >
      > --
      > Ignacio Machin,
      > ignacio.machin AT dot.state.fl.us
      > Florida Department Of Transportation
      >
      > "Karin" <kl@inxl.se> wrote in message
      > news:u3ylTYqSDH A.2852@tk2msftn gp13.phx.gbl...[color=green]
      > > Hi,
      > > Can anyone explain to me why SelectedIndex is automatically changed to 0
      > > when I set it to -1?
      > >
      > > This happens when I set SelectedIndex = -1 from the click-eventhandler[/color][/color]
      of[color=blue]
      > a[color=green]
      > > button. My ListBox is bound to an ArrayList.
      > >
      > > Thanks! /K
      > >
      > >[/color]
      >
      >[/color]


      Comment

      Working...