|
|
|
|
|
Dicas
|
|
Visual Basic (ActiveX/Controles/DLL)
|
|
|
Título da Dica: como colocar check boxes em duas colunas da listView
|
|
|
|
Postada em 5/4/2006 por Geronimo
para simular uma funcionalidade parecida. Para testar o exemplo abaixo vc terá que criar um form com 1 listview, 1 imagelist com 2 imagens de 12x12 a primeira é o checkbox vazio e a segunda é ele marcado.
Private Type lvwMsgInfo x As Long y As Long Flgs As Long Itm As Long SubItm As Long End Type
Private MaxSelected As ListItem
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal lMsg As Long, ByVal wParam As Long, lParam As Any) As Long Private Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As Long) As Long
Private lvwMsg As lvwMsgInfo
Private Sub Form_Load()
Dim LI As ListItem Dim SubLI As ListSubItem ListView1.FullRowSelect = True Set LI = ListView1.ListItems.Add(, , "Item 1") Set SubLI = LI.ListSubItems.Add(, , "SubItem 1", 1) SubLI.Tag = "0" Set LI = ListView1.ListItems.Add(, , "Item 2") Set SubLI = LI.ListSubItems.Add(, , "SubItem 2", 1) SubLI.Tag = "0" End Sub
Private Sub ListView1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
Set MaxSelected = ListView1.SelectedItem LockWindowUpdate ListView1.hwnd End Sub
Private Sub ListView1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim TXT As String Dim Linha As Integer Dim Coluna As Integer Dim Valor As Boolean ' Chama a API lvwMsg.x = x / Screen.TwipsPerPixelX lvwMsg.y = y / Screen.TwipsPerPixelY SendMessage ListView1.hwnd, 4153, 0, lvwMsg ' Testa o click If lvwMsg.Flgs And 14 Then Linha = lvwMsg.Itm + 1 ' Se SubItem for 0 o click foi no item If lvwMsg.SubItm > 0 Then Coluna = lvwMsg.SubItm + 1 Else Coluna = 1 End If End If ' O Valor de cada item da coluna está no tag do item If Coluna = 2 And x < ListView1.ColumnHeaders(2).Left + (12 * 15) Then Valor = CBool(ListView1.SelectedItem.ListSubItems(1).Tag) Valor = Not Valor ListView1.SelectedItem.ListSubItems(1).ReportIcon = Abs(Valor) + 1 ListView1.SelectedItem.ListSubItems(1).Tag = Valor If Not MaxSelected Is Nothing Then Set ListView1.SelectedItem = MaxSelected End If End If
LockWindowUpdate 0 End Sub
|
|
|
|
|