ListView 
Author Message
 ListView

I can't find "Key" property in ListItem.

I want to store Items into ListView with a database table primary key.

How i can work around this?

Regards, Dmitry Shuklin



Sat, 31 May 2003 00:15:40 GMT  
 ListView
I believe you can inherit ListItem and add your own properties.

--
Jonathan Allen


Quote:
> I can't find "Key" property in ListItem.

> I want to store Items into ListView with a database table primary key.

> How i can work around this?

> Regards, Dmitry Shuklin



Sat, 31 May 2003 01:27:47 GMT  
 ListView
Maybe this is too simple, but can you just add your string as a listitem and
just hide that columnheader?

-Pickle


Quote:
> I believe you can inherit ListItem and add your own properties.

> --
> Jonathan Allen



> > I can't find "Key" property in ListItem.

> > I want to store Items into ListView with a database table primary key.

> > How i can work around this?

> > Regards, Dmitry Shuklin



Sat, 31 May 2003 05:31:48 GMT  
 ListView
Make that ListSubItem (an extra string when adding a ListItem).

-Pickle


Quote:
> Maybe this is too simple, but can you just add your string as a listitem
and
> just hide that columnheader?

> -Pickle



> > I believe you can inherit ListItem and add your own properties.

> > --
> > Jonathan Allen



> > > I can't find "Key" property in ListItem.

> > > I want to store Items into ListView with a database table primary key.

> > > How i can work around this?

> > > Regards, Dmitry Shuklin



Sat, 31 May 2003 05:57:56 GMT  
 ListView

Quote:

>I believe you can inherit ListItem and add your own properties.

How i can find this item by value in my property?

Regards, Dmitry



Sat, 31 May 2003 16:37:56 GMT  
 ListView
Here's a code sample that creates a new type, ListItem2, with a string
property Table.
Note the code in listView1_DoubleClick to see that you can cast the ListItem
back into a ListItem2 and get your custom property Table.
NOTE: The following code should be pasted into a new VB form file. You WILL
NOT be able to look at the form in design mode because I've added a second
public class to the same file. You would normally break this into its own
separate .VB file.

The main changes are:
1. Added new class, ListItem2.
2. In the Form's Constructor (New), I added 3 ListItem2 objects
3. In the ListView1's DoubleClick, I cast the first selected item into a
ListItem2 object to display the Table property.

============================

Imports System.ComponentModel
Imports System.Drawing
Imports System.WinForms

Public Class ListItem2
    Inherits ListItem

    Private mTable As String

    Public Sub New(ByVal [text] As String, ByVal subItems() As String, ByVal
table As String)
        MyBase.New([text], subItems)

        Me.mTable = table
    End Sub

    Public Property Table() As String
        Get
            Table = mTable
        End Get
        Set
            mTable = value
        End Set
    End Property

End Class

Public Class Form1
    Inherits System.WinForms.Form

    Public Sub New()
        MyBase.New()

        Form1 = Me

        'This call is required by the Win Form Designer.
        InitializeComponent()

        listView1.ListItems.Add(New ListItem2("Item1", New String() {"item1,
col2", "item1, col3"}, "table1"))
        listView1.ListItems.Add(New ListItem2("Item2", New String() {"item2,
col2", "item2, col3"}, "table2"))
        listView1.ListItems.Add(New ListItem2("Item3", New String() {"item3,
col2", "item3, col3"}, "table3"))
    End Sub

    'Form overrides dispose to clean up the component list.
    Public Overrides Sub Dispose()
        MyBase.Dispose()
        components.Dispose()
    End Sub

#Region " Windows Form Designer generated code "

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.Container
    Private ColumnHeader3 As System.WinForms.ColumnHeader
    Private ColumnHeader2 As System.WinForms.ColumnHeader
    Private ColumnHeader1 As System.WinForms.ColumnHeader
    Private WithEvents btnClose As System.WinForms.Button
    Private WithEvents ListView1 As System.WinForms.ListView

    Dim WithEvents Form1 As System.WinForms.Form

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.
    'Do not modify it using the code editor.
    Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container()
        Me.ListView1 = New System.WinForms.ListView()
        Me.btnClose = New System.WinForms.Button()
        Me.ColumnHeader3 = New System.WinForms.ColumnHeader()
        Me.ColumnHeader2 = New System.WinForms.ColumnHeader()
        Me.ColumnHeader1 = New System.WinForms.ColumnHeader()




        ListView1.Location = New System.Drawing.Point(8, 8)
        ListView1.Size = New System.Drawing.Size(280, 224)
        ListView1.HideSelection = False
        ListView1.FullRowSelect = True
        ListView1.View = System.WinForms.View.Report
        ListView1.ForeColor = System.Drawing.SystemColors.WindowText
        ListView1.TabIndex = 0
        ListView1.Anchor = System.WinForms.AnchorStyles.All
        Dim a__1(3) As System.WinForms.ColumnHeader
        a__1(0) = ColumnHeader1
        a__1(1) = ColumnHeader2
        a__1(2) = ColumnHeader3
        ListView1.Columns.All = a__1

        btnClose.Location = New System.Drawing.Point(208, 240)
        btnClose.Size = New System.Drawing.Size(80, 24)
        btnClose.TabIndex = 1
        btnClose.Anchor = System.WinForms.AnchorStyles.BottomRight
        btnClose.Text = "Close"

        ColumnHeader3.Text = "ColumnHeader"
        ColumnHeader3.TextAlign = System.WinForms.HorizontalAlignment.Left

        ColumnHeader2.Text = "ColumnHeader"
        ColumnHeader2.TextAlign = System.WinForms.HorizontalAlignment.Left

        ColumnHeader1.Text = "ColumnHeader"
        ColumnHeader1.TextAlign = System.WinForms.HorizontalAlignment.Left
        Me.Text = "Form1"
        Me.StartPosition = System.WinForms.FormStartPosition.CenterScreen
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)

        Me.Controls.Add(btnClose)
        Me.Controls.Add(ListView1)
    End Sub

#End Region

    Protected Sub btnClose_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnClose.Click
        Me.Close()
    End Sub

    Protected Sub listView1_DoubleClick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles listView1.DoubleClick
        Dim li As ListItem2 = CType(listView1.SelectedItems(0), ListItem2)
        MessageBox.Show(li.Table)
    End Sub

End Class



Sun, 01 Jun 2003 04:42:18 GMT  
 ListView
I assume you would have to loop through all the objects until you found it.
I haven't gotten into it real deep yet, I take anything I say with a grain
of salt.

--
Jonathan Allen


Quote:


> >I believe you can inherit ListItem and add your own properties.

> How i can find this item by value in my property?

> Regards, Dmitry



Sun, 01 Jun 2003 04:28:55 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Drag an item of Listview to another position of the same ListView

2. Ownerdraw works with ListView 5.0 but not with ListView 6.0

3. Dragging from ListView to ListView or TreeView

4. Listview vs. Extended Listview

5. Listview: synchronize two listviews

6. Ownerdraw works with ListView 5.0 but not with ListView 6.0 (in this sample)

7. Listview: check if an item in current listview

8. ListView to ListView copying ???

9. ListView column width = ListView width ?

10. changing the background of a listview item in the listview control

11. Listview Control - moving items from one listview to another

12. Listview: Determining ListView from ListItem????

 

 
Powered by phpBB® Forum Software