ListView Bug (I think)

Mikecrosoft
01-13-2004, 01:46 PM
Hi I'm using this code for add a list of Employees in the Table.


Dim dsPersonal As New DataSet
Dim Itm As ListViewItem
Dim I As Integer

mdaDatos.SelectCommand = New OleDb.OleDbCommand("SELECT * FROM Personal", gCnn)
mdaDatos.Fill(dsPersonal, "Personal")

lvwPersonal.Items.Clear()

For I = 0 To dsPersonal.Tables("Personal").Rows.Count - 1
With dsPersonal.Tables("Personal").Rows(I)
Itm = lvwPersonal.Items.Add(!PrsNombre)
Itm.Tag = !PrsID
Itm.SubItems(0).Text = !PrsLog
End With
Next I
dsPersonal.Dispose()


But the the SubItem(0) is not updating the second column, it update the First one. Why ?

Thanks

Naghual
01-13-2004, 01:50 PM
Use
Set Itm = lvwPersonal.Items.Add(!PrsNombre)

00100b
01-13-2004, 01:53 PM
SubItems is a Base-1 index and not a Base-0 index.

Hi I'm using this code for add a list of Employees in the Table.


Dim dsPersonal As New DataSet
Dim Itm As ListViewItem
Dim I As Integer

mdaDatos.SelectCommand = New OleDb.OleDbCommand("SELECT * FROM Personal", gCnn)
mdaDatos.Fill(dsPersonal, "Personal")

lvwPersonal.Items.Clear()

For I = 0 To dsPersonal.Tables("Personal").Rows.Count - 1
With dsPersonal.Tables("Personal").Rows(I)
Itm = lvwPersonal.Items.Add(!PrsNombre)
Itm.Tag = !PrsID
Itm.SubItems(0).Text = !PrsLog
End With
Next I
dsPersonal.Dispose()


But the the SubItem(0) is not updating the second column, it update the First one. Why ?

Thanks

Mikecrosoft
01-13-2004, 02:32 PM
Sorry, this is a .NET Question, I posted here, sorry :S

I'm using .NET


Nope I need to update the second column with !PrsLog NOT the first one, also, I used -1 as index, it gives me an error ;)

Mikecrosoft
01-13-2004, 02:38 PM
Nope I need to update the second column with !PrsLog NOT the first one, also, I used -1 as index, it gives me an error ;)

00100b
01-14-2004, 05:02 AM
Not negative one, but one. (Base-1 = Base One).

Grimfort
01-14-2004, 07:05 AM
But the the SubItem(0) is not updating the second column, it update the First one. Why ?

Thanks

You dont have any sub-items in that listviewitem (you just made it), which is why using (1) will fail. The 0 is the same as Itm.Text.
Just use this:


Itm.SubItems.Add(!PrsLog)

Mikecrosoft
01-14-2004, 08:54 AM
Grimfort: It works !!! :D

but I have adoubt, why I need to add, because I added the columns in design view ???

Thanks

Grimfort
01-14-2004, 10:19 AM
Grimfort: It works !!! :D

but I have adoubt, why I need to add, because I added the columns in design view ???

Thanks

Remeber that everything in .net is a class. The data is completly seperate from the control, (good and bad idea). For instance, if you just do this

dim lstItem as New ListBoxItem("help")

then it will create a new class for you. It doesnt live anywhere (other then ref the variable), and doesnt do anything. You can then add that directly to a listview (or many if you like).

MyListView.Add(lstItem)

You can have a listitem that has 100 subitems, but if the control thats looking at it only has 1 column, then you will only see 1 column.
You can do cool stuff like copy (as long as its byref) a listitem out of one into another listview, and if you edit one of them, then the other one changes as they are the same item. I suspect you can also inherit from a listitem and put other object types into a listview control, to give you even more scope for change.

You will see this more if you try to use a listbox, in which you can put anything (classes, strings, numbers), it just uses the class's .ToString function to get the view, and when you get the selected object, it returns the object as you put it in.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum