469,909 Members | 1,683 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,909 developers. It's quick & easy.

ListView.SelectedItems.Clear

Ok I'm having a problem with a listview. I have a listview on a WinForm
called ProgramInformationFrm. 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.Visible = False
ProgramInformationFrm.ProgramsLV.SelectedItems.Cle ar()
ProgramInformationFrm.ProgramsLV.Items.Clear()
Dim item As New ListViewItem(tmpNCFile)
ProgramInformationFrm.ProgramsLV.Items.Add(item)
ProgramInformationFrm.ProgramsLV.Focus()
ProgramInformationFrm.ProgramsLV.Items(0).Selected = True
ProgramInformationFrm.ShowDialog()

Mar 13 '06 #1
2 5996
On Mon, 13 Mar 2006 06:59:27 -0800, Mike
<Mi**@discussions.microsoft.com> wrote:
Ok I'm having a problem with a listview. I have a listview on a WinForm
called ProgramInformationFrm. 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.Visible = False
ProgramInformationFrm.ProgramsLV.SelectedItems.Cle ar()
ProgramInformationFrm.ProgramsLV.Items.Clear()
Dim item As New ListViewItem(tmpNCFile)
ProgramInformationFrm.ProgramsLV.Items.Add(item)
ProgramInformationFrm.ProgramsLV.Focus()
ProgramInformationFrm.ProgramsLV.Items(0).Selected = True
ProgramInformationFrm.ShowDialog()


1) Focus() (ProgramsLV.Focus()) 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
Mar 13 '06 #2
Ok got it working. To pass the value I am doing this;
ProgramInformationFrm.ProgramsLV.SelectedItems.Cle ar()
ProgramInformationFrm.ProgramsLV.Items.Clear()
Dim item As New ListViewItem(tmpNCFile)
ProgramInformationFrm.ProgramsLV.Items.Add(item)
ProgramInformationFrm.ProgramsLV.Items(0).Selected = True
ProgramInformationFrm.ProgramsLV.Select()
ProgramInformationFrm.ProgramsLV.Items(0).Focused = True
ProgramInformationFrm.ShowDialog()
On form load of ProgramInformationFrm I know use
tmpNCFile = Me.ProgramsLV.Items(0).Text instead of
Me.ProgramsLV.SelectedItems.Item(0).text to return value of the first item
in the list.
"gene kelley" wrote:
On Mon, 13 Mar 2006 06:59:27 -0800, Mike
<Mi**@discussions.microsoft.com> wrote:
Ok I'm having a problem with a listview. I have a listview on a WinForm
called ProgramInformationFrm. 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.Visible = False
ProgramInformationFrm.ProgramsLV.SelectedItems.Cle ar()
ProgramInformationFrm.ProgramsLV.Items.Clear()
Dim item As New ListViewItem(tmpNCFile)
ProgramInformationFrm.ProgramsLV.Items.Add(item)
ProgramInformationFrm.ProgramsLV.Focus()
ProgramInformationFrm.ProgramsLV.Items(0).Selected = True
ProgramInformationFrm.ShowDialog()


1) Focus() (ProgramsLV.Focus()) 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

Mar 14 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

13 posts views Thread by Maheshkumar.R | last post: by
5 posts views Thread by John Devlon | last post: by
7 posts views Thread by John Devlon | last post: by
1 post views Thread by =?Utf-8?B?SmVzcGVyLCBEZW5tYXJr?= | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.