IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VB.NET Discussion :

Listview : View.Details, image + texte dans plusieurs colonnes


Sujet :

VB.NET

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre émérite Avatar de methylene
    Profil pro
    Inscrit en
    Février 2010
    Messages
    659
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Février 2010
    Messages : 659
    Par défaut Listview : View.Details, image + texte dans plusieurs colonnes
    Bonjour,

    J'ai une petite question sur le Listview :

    J'ai 2 colonnes, et je souhaite dans ces deux colonnes avoir un texte et une image dans chacune. J'utilise pour cela la propriété :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    ListView1.View = View.Details
    Voici mon code

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
            ListView1.SmallImageList = ImageList1
            ListView1.GridLines = False
            ListView1.View = View.Details
            ListView1.Columns.Add("Column1", 80, HorizontalAlignment.Left)
            ListView1.Columns.Add("Column2", 80, HorizontalAlignment.Left)
            ListView1.HeaderStyle = ColumnHeaderStyle.None
     
            Dim listtest1 As New ListViewItem
     
            listtest1.Text = "Texte1"
            listtest1.ImageIndex = 0
            listtest1.SubItems.Add("Texte2")
            listtest1.ImageIndex = 1
            ListView1.Items.Add(listtest1)
    Le problème c'est que pour remplir ma 2ème colonne j'utilise Subitems.Add, mais je ne vois pas comment donner à la deuxième colonne (pour mon ListViewItem listtest1) l'indice de l'image dans mon ImageList, la propriété

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    listtest1.SubItems.ImageIndex
    n'existant pas.

    Et même dans le

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    listtest1.SubItems.Add("Texte2")
    il n'y a pas de propriétés concernant l'image après celui du texte.

    Merci de votre aide.

  2. #2
    Membre émérite Avatar de methylene
    Profil pro
    Inscrit en
    Février 2010
    Messages
    659
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Février 2010
    Messages : 659
    Par défaut
    Histoire de voir ce que cela donne voila ce que je cherche à faire (en pièce jointe).

    J'arrive à mettre une image + texte dans la première colonne, mais dans les autres colonnes je n'arrive à mettre que du texte (Subitems).

  3. #3
    Membre Expert
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    700
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2006
    Messages : 700
    Par défaut
    Bonjour,
    en adaptant le code de Carlos Carvalho de son OAKListView 1.0 :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    '*************************************************************************
    'OAKListView 1.0
    '10/02/2004
    'Developer: Carlos Carvalho
    'carvalho@flag.com.br
    '+55 31 99440862 / +55 31 32616977
    '**************************************************************************
     
    Imports System.Windows.Forms
    Imports System.Runtime.InteropServices
     
    Public Class OAKListView
        Inherits ListView
        <StructLayoutAttribute(LayoutKind.Sequential)> _
        Public Structure LV_ITEM
            Public mask As UInt32
            Public iItem As Int32
            Public iSubItem As Int32
            Public state As UInt32
            Public stateMask As UInt32
            Public pszText As [String]
            Public cchTextMax As Int32
            Public iImage As Int32
            Public lParam As IntPtr
        End Structure
     
        Public Const LVM_FIRST As Int32 = &H1000
        Public Const LVM_GETITEM As Int32 = LVM_FIRST + 5
        Public Const LVM_SETITEM As Int32 = LVM_FIRST + 6
        Public Const LVIF_TEXT As Int32 = &H1
        Public Const LVIF_IMAGE As Int32 = &H2
     
        Public Const LVW_FIRST As Integer = &H1000
        Public Const LVM_GETEXTENDEDLISTVIEWSTYLE As Integer = LVW_FIRST + 54
     
        Public Const LVS_EX_GRIDLINES As Integer = &H1
        Public Const LVS_EX_SUBITEMIMAGES As Integer = &H2
        Public Const LVS_EX_CHECKBOXES As Integer = &H4
        Public Const LVS_EX_TRACKSELECT As Integer = &H8
        Public Const LVS_EX_HEADERDRAGDROP As Integer = &H10
        Public Const LVS_EX_FULLROWSELECT As Integer = &H20
        ' applies to report mode only
        Public Const LVS_EX_ONECLICKACTIVATE As Integer = &H40
     
        ' pointer to struct of LV_ITEM
        ''' Changing the style of listview to accept image on subitems
        Protected Overrides Sub OnHandleCreated(ByVal e As EventArgs)
            MyBase.OnHandleCreated(e)
            ' Change the style of listview to accept image on subitems
            Dim m As System.Windows.Forms.Message = New Message()
            m.HWnd = Me.Handle
            m.Msg = LVM_GETEXTENDEDLISTVIEWSTYLE
            'm.LParam = CType(LVS_EX_GRIDLINES Or LVS_EX_FULLROWSELECT Or LVS_EX_SUBITEMIMAGES Or LVS_EX_CHECKBOXES Or LVS_EX_TRACKSELECT, IntPtr)
            m.LParam = CType(LVS_EX_GRIDLINES Or LVS_EX_SUBITEMIMAGES, IntPtr)
            m.WParam = IntPtr.Zero
            Me.WndProc(m)
        End Sub
     
        ' handle to destination window 
        ' message 
        ' first message parameter 
        <DllImport("user32.dll")> _
        Public Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As Integer
            ' second message parameter 
        End Function
     
        ' handle to destination window 
        ' message 
        <DllImport("user32.dll")> _
        Public Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal msg As Int32, ByVal wParam As Int32, ByRef lParam As LV_ITEM) As Boolean
        End Function
     
    End Class
    et tester dans un form, cela fonctionne chez moi :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    Imports System.Drawing
    Imports System.Collections
    Imports System.ComponentModel
    Imports System.Windows.Forms
    Imports System.Data
    Imports ListviewSubitemsIcones.OAKListView
     
    Public Class Form1
     
        Private listView1 As OAKListView = New OAKListView
     
        Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
     
            CreateMyListView()
     
        End Sub
     
        Private Sub CreateMyListView()
            ' Create a new ListView control.
            'Dim listView1 As New OAKListView
            listView1.Bounds = New Rectangle(New Point(10, 10), New Size(424, 200))
            ' Set the view to show details.
            listView1.View = Windows.Forms.View.Details
            ' Allow the user to edit item text.
            listView1.LabelEdit = True
            ' Allow the user to rearrange columns.
            listView1.AllowColumnReorder = True
            ' Display check boxes.
            listView1.CheckBoxes = True
            ' Select the item and subitems when selection is made.
            listView1.FullRowSelect = True
     
            ' Create three items and three sets of subitems for each item.
            Dim item1 As New ListViewItem("item1", imageIndex:=0)
            ' Place a check mark next to the item.
            'item1.Checked = True
            item1.SubItems.Add("1")
            'addImagSubItem() '(0, 1, "Paste", 1)
            item1.SubItems.Add("2")
            'addImagSubItem() '(1, 2, "2", 2)
            item1.SubItems.Add("3")
            'addImagSubItem() '(0, 3, "3", 3)
            Dim item2 As New ListViewItem("item2", 1)
            item2.SubItems.Add("4")
            item2.SubItems.Add("5")
            item2.SubItems.Add("6")
            Dim item3 As New ListViewItem("item3", 2)
            ' Place a check mark next to the item.
            'item3.Checked = True
            item3.SubItems.Add("7")
            item3.SubItems.Add("8")
            item3.SubItems.Add("9")
            ' Create columns for the items and subitems.
            listView1.Columns.Add("Item Column", 100, HorizontalAlignment.Left)
            listView1.Columns.Add("Column 2", 80, HorizontalAlignment.Left)
            listView1.Columns.Add("Column 3", 120, HorizontalAlignment.Left)
            listView1.Columns.Add("Column 4", 120, HorizontalAlignment.Center)
            'Add the items to the ListView.
            listView1.Items.AddRange(New ListViewItem() {item1, item2, item3})
     
            'Assign the ImageList objects to the ListView.
            listView1.SmallImageList = ImageList1
     
            ' Add the ListView to the control collection.
            Me.Controls.Add(listView1)
     
            'Après avoir créé le contrôle on ajoute image et texte aux subItems.
            addImagSubItem(0, 1, "Paste", 1)
            addImagSubItem(0, 2, "Cut", 0)
     
        End Sub 'CreateMyListView
     
        Private Sub addImagSubItem(ByVal row As Integer, ByVal col As Integer, ByVal text As String, ByVal numImageList As Integer)
            Dim lvi As New OAKListView.LV_ITEM()
            ' Row
            lvi.iItem = row
            ' Column
            lvi.iSubItem = col
            lvi.pszText = text
            lvi.mask = OAKListView.LVIF_IMAGE Or OAKListView.LVIF_TEXT
            ' Image index on imagelist
            lvi.iImage = numImageList
            OAKListView.SendMessage(listView1.Handle, OAKListView.LVM_SETITEM, 0, lvi)
        End Sub
     
    End Class

  4. #4
    Membre émérite Avatar de methylene
    Profil pro
    Inscrit en
    Février 2010
    Messages
    659
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Février 2010
    Messages : 659
    Par défaut
    Salut,

    J'avais également récuperer cette source en C#, que j'avais traduit en vb.net et tenter de modifier pour pouvoir l'utiliser, mais je n'y étais pas arrivé, je vais donc regarder ce que tu as fait, merci.

    J'avais personnellement rencontré un problème au niveau de l'espace d enom (NAME SPACE).

  5. #5
    Membre émérite Avatar de methylene
    Profil pro
    Inscrit en
    Février 2010
    Messages
    659
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Février 2010
    Messages : 659
    Par défaut
    Bon bien je te remercie, ce qui serait bien maintenant c'est dans faire une dll, et de l'ajouter en tant que nouvelle référence merci.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Recherche VBA dans plusieurs colonnes.
    Par madchemiker dans le forum VBA Access
    Réponses: 3
    Dernier message: 12/07/2007, 13h09
  2. [C#] DataGridView image + texte dans une cellule
    Par nitrous007 dans le forum Windows Forms
    Réponses: 1
    Dernier message: 28/06/2007, 13h08
  3. compter dans plusieur colonne
    Par fabrice44 dans le forum Macros et VBA Excel
    Réponses: 1
    Dernier message: 23/04/2007, 17h19
  4. Recherche plein texte dans plusieurs tables
    Par GCAccess dans le forum Access
    Réponses: 1
    Dernier message: 08/02/2007, 18h29
  5. Recherche dans plusieurs colonnes d'une table
    Par yoline dans le forum Access
    Réponses: 4
    Dernier message: 26/07/2006, 11h58

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo