ListView.SelectedItems.Clear

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

    #1

    ListView.SelectedItems.Clear

    Ok I'm having a problem with a listview. I have a listview on a WinForm
    called ProgramInformat ionFrm. I call this from from 2 other forms. One is
    ProgramSearch Frm, the other is OpenNCFrm. The search form accepts criteria
    from a user ans searches a sql table for any nc program that matches the
    criteria. The open form gives the user a list of programs that have not been
    added to table yet. Ok, enough background. What is happening is if I use the
    search from and get 8 results the first item is selected per my code. Now I
    close that form get into the add form, add a new record. It writes to the
    table, clears the listview on the info table, and then shows the infofrom.
    The item is not selected, but is the only item in the list. It should be
    selected. Also in debug I still have the previous value from the first time
    the form was shown.
    Here's my code
    OpenNCFrm.Visib le = False
    ProgramInformat ionFrm.Programs LV.SelectedItem s.Clear()
    ProgramInformat ionFrm.Programs LV.Items.Clear( )
    Dim item As New ListViewItem(tm pNCFile)
    ProgramInformat ionFrm.Programs LV.Items.Add(it em)
    ProgramInformat ionFrm.Programs LV.Focus()
    ProgramInformat ionFrm.Programs LV.Items(0).Sel ected = True
    ProgramInformat ionFrm.ShowDial og()

  • gene kelley

    #2
    Re: ListView.Select edItems.Clear

    On Mon, 13 Mar 2006 06:59:27 -0800, Mike
    <Mike@discussio ns.microsoft.co m> wrote:
    [color=blue]
    >Ok I'm having a problem with a listview. I have a listview on a WinForm
    >called ProgramInformat ionFrm. I call this from from 2 other forms. One is
    >ProgramSearc h Frm, the other is OpenNCFrm. The search form accepts criteria
    >from a user ans searches a sql table for any nc program that matches the
    >criteria. The open form gives the user a list of programs that have not been
    >added to table yet. Ok, enough background. What is happening is if I use the
    >search from and get 8 results the first item is selected per my code. Now I
    >close that form get into the add form, add a new record. It writes to the
    >table, clears the listview on the info table, and then shows the infofrom.
    >The item is not selected, but is the only item in the list. It should be
    >selected. Also in debug I still have the previous value from the first time
    >the form was shown.
    >Here's my code
    >OpenNCFrm.Visi ble = False
    > ProgramInformat ionFrm.Programs LV.SelectedItem s.Clear()
    > ProgramInformat ionFrm.Programs LV.Items.Clear( )
    > Dim item As New ListViewItem(tm pNCFile)
    > ProgramInformat ionFrm.Programs LV.Items.Add(it em)
    > ProgramInformat ionFrm.Programs LV.Focus()
    > ProgramInformat ionFrm.Programs LV.Items(0).Sel ected = True
    >ProgramInforma tionFrm.ShowDia log()[/color]

    1) Focus() (ProgramsLV.Foc us()) usually has no meaning before a form
    is displayed as that is usually determined by what control on the form
    has the TabStop Index of "0", or, focus of a particular control is
    called in the form's activated event.
    (Note: In VB6, changing a TabIndex in a control reindexed the other
    controls that had a TabIndex. I don't know about earlier versions,
    but in VB2005, changing a TabIndex of a control does not reindex the
    others, so you can wind up with more than one control with the same
    index value and unpredicitable results.)

    2) Run the .exe in bin\debug a couple of time and see if you are
    getting the expected value results.

    Gene

    Comment

    • Mike

      #3
      Re: ListView.Select edItems.Clear

      Ok got it working. To pass the value I am doing this;
      ProgramInformat ionFrm.Programs LV.SelectedItem s.Clear()
      ProgramInformat ionFrm.Programs LV.Items.Clear( )
      Dim item As New ListViewItem(tm pNCFile)
      ProgramInformat ionFrm.Programs LV.Items.Add(it em)
      ProgramInformat ionFrm.Programs LV.Items(0).Sel ected = True
      ProgramInformat ionFrm.Programs LV.Select()
      ProgramInformat ionFrm.Programs LV.Items(0).Foc used = True
      ProgramInformat ionFrm.ShowDial og()
      On form load of ProgramInformat ionFrm I know use
      tmpNCFile = Me.ProgramsLV.I tems(0).Text instead of
      Me.ProgramsLV.S electedItems.It em(0).text to return value of the first item
      in the list.


      "gene kelley" wrote:
      [color=blue]
      > On Mon, 13 Mar 2006 06:59:27 -0800, Mike
      > <Mike@discussio ns.microsoft.co m> wrote:
      >[color=green]
      > >Ok I'm having a problem with a listview. I have a listview on a WinForm
      > >called ProgramInformat ionFrm. I call this from from 2 other forms. One is
      > >ProgramSearc h Frm, the other is OpenNCFrm. The search form accepts criteria
      > >from a user ans searches a sql table for any nc program that matches the
      > >criteria. The open form gives the user a list of programs that have not been
      > >added to table yet. Ok, enough background. What is happening is if I use the
      > >search from and get 8 results the first item is selected per my code. Now I
      > >close that form get into the add form, add a new record. It writes to the
      > >table, clears the listview on the info table, and then shows the infofrom.
      > >The item is not selected, but is the only item in the list. It should be
      > >selected. Also in debug I still have the previous value from the first time
      > >the form was shown.
      > >Here's my code
      > >OpenNCFrm.Visi ble = False
      > > ProgramInformat ionFrm.Programs LV.SelectedItem s.Clear()
      > > ProgramInformat ionFrm.Programs LV.Items.Clear( )
      > > Dim item As New ListViewItem(tm pNCFile)
      > > ProgramInformat ionFrm.Programs LV.Items.Add(it em)
      > > ProgramInformat ionFrm.Programs LV.Focus()
      > > ProgramInformat ionFrm.Programs LV.Items(0).Sel ected = True
      > >ProgramInforma tionFrm.ShowDia log()[/color]
      >
      > 1) Focus() (ProgramsLV.Foc us()) usually has no meaning before a form
      > is displayed as that is usually determined by what control on the form
      > has the TabStop Index of "0", or, focus of a particular control is
      > called in the form's activated event.
      > (Note: In VB6, changing a TabIndex in a control reindexed the other
      > controls that had a TabIndex. I don't know about earlier versions,
      > but in VB2005, changing a TabIndex of a control does not reindex the
      > others, so you can wind up with more than one control with the same
      > index value and unpredicitable results.)
      >
      > 2) Run the .exe in bin\debug a couple of time and see if you are
      > getting the expected value results.
      >
      > Gene
      >[/color]

      Comment

      Working...