ListView Troubles

  • Thread starter Thread starter Mr. B
  • Start date Start date
M

Mr. B

VB.net issue here.

I've a strange event that I can't seem to figure out...

On my Form, I've a TabControl (two Tabs)...

On my first tab, I load an Ascii file and dump some info onto my ListView
(which is located on my other Tab).

Now IF I click on the 2nd Tab... the Info IS to be sorted out - as I've set
the properties to SORT = Ascending.

But IF I load my data... and DO NOT change tabs... I've found that the
information on the Listview is NOT sorted. At least, not until I click on the
Tab and display the Listview!!!! (which the info is sorted out).

WTF? I don't understand this?

Regards,

Bruce F
 
Mr. B.

This is a kind of usual question about the tabpage. To answer it with a
general answer, AFAIK, are actions in the controls taken when they are
showed (activated).

I hope this helps,

Cor
 
Cor Ligthert said:
Mr. B.

This is a kind of usual question about the tabpage. To answer it with a
general answer, AFAIK, are actions in the controls taken when they are
showed (activated).

Thanks Cor... That was the first place I looked :(

Here is what I have on the TabControl:

Private Sub TabControl1_Click(ByVal eventSender As System.Object, ByVal
eventArgs As System.EventArgs) Handles TabControl1.Click
' Do Things Based on Active Tab Selected

If TabControl1.TabPages(0).Focus() = True Then
btnAddTabs.Enabled = False
btnModTabs.Enabled = False
btnDelTabs.Enabled = False
lblDwgsDelete.Text = "0"
lblDwgsAdded.Text = "0"
txbDwgRename.Text = ""
lblDwgRename.Text = ""
cmbAddDwgTabs.SelectedIndex = 0
Exit Sub
End If

End Sub

So I don't do anything via the TabControl. And like I said, all I do is to
change tabs (and there I don't click on anything). Very strange. But I'll
have to find the answer as it's driving me nuts.

There will be times where changing tabs is not done so I must figure this one
out. I just can't see why it doesn't sort UNLESS it is visible.

Regards,

Bruce F
 
Since you did not show the code related to the ListView, I am bit hesitant
to ask, do you have the ListView's ListViewItemSorter property set to a
valid IComparer object after loading ListViewItems, like:

foreach (<you data>)
{
ListViewItem item=new ListViewItem()
...
MyListViewItems.Add(item)
}

//This line of code sorts the ListView
MyListView.ListViewItemSorter=<myIComparer>

If you do not have this line of code, the listView will not be sorted. If it
looks like sorted, it is just because the data happens to be in sorted order

I do not think whether the ListView being sorted or not has anything to do
with clicking on TablControl's tab unless you set ListViewItemSorter in that
event handler, which you did not according to your reply to the other post.
 
Norman Yuan said:
Since you did not show the code related to the ListView, I am bit hesitant
to ask, do you have the ListView's ListViewItemSorter property set to a
valid IComparer object after loading ListViewItems, like:

Well... that's because there IS no code to show (grin). Here is the basics...

1) A TabControl with Two (2) tabs.

2) A Standard ListView with Sorted set in the Properties, etc. This is on the
2nd Tab or Tab(1).

3) I load a TEXT file and dumps some 'unsorted' into into the Listbox (two
columns).

4) Now if I build and Array with the Listview info as is, the dump the Array
info into an unsorted Listbox (for Testing purposes), the info is NOT sorted.

However, IF I do #1 to #2 and 'then' do nothing more that switch from Tab(0)
to Tab(1) and back to Tab(0)... and then do #3, the listbox items ARE sorted.

So what I've done as a bandaid was to add another ListView on Tab(0) and hide
it behind something. Load my Text stuff to this and then dump it to my Tab(1)
ListView. And this works. A poor code way of doing it. But performance is
nothing as there is only <100 line items in the ListView.
foreach (<you data>)
{
ListViewItem item=new ListViewItem()
...
MyListViewItems.Add(item)
}

//This line of code sorts the ListView
MyListView.ListViewItemSorter=<myIComparer>

I'll check this out. As I'd rather not have two ListView's (simply bad coding
if for no other reason).

Thanks!

Bruce F
 
Back
Top