Hi all,
Help me please, I don't know whats wrong with the code. I attach my file, if you need to review the code.
I'm working with listview here. I use dummy data, to make it more simpler. I want my listview autorefresh whenever i press F1 (to refer to 2nd database), and F2 (to refer back to 1st database), the default need to show 1st database
see below pic, table B5:D25 (beige), is the 1st database. and G5:I16 (blue) is the 2nd database
Listview.JPG
I want to show the listview listitems, like this
if
G1 (yellow) was blank, indicated by H1 (istext = false), then
show 1st database
else
G1 (yellow) was filled, indicated by H1 (istext = true)
show 2nd database
and here's my current code,
telling if
press F1, selection item will be copied to G1 - Listview gonna refreshed and showed 2nd database.
press F2, content/text in G1 will be deleted - listview gonna refreshed and showed 1st database
currently
1. when first time running, 1st database wasn't showed, press alt/shift/ctrl will showed them
2. the listview not immediately refreshed after press F1, need to press alt/shift/ctrl to refresh
3. the listview not immediately refreshed after press F2, need to press alt/shift/ctrl to refresh
4. i can't use up/down key direction to select within the listview.
Private Sub UserForm_Initialize()
'listview format
With ListView1
.Gridlines = True
.View = lvwReport
.FullRowSelect = True
.ColumnHeaders.Add Text:="Menu List", Width:=128
.ColumnHeaders.Add Text:="Basic Ingredients", Width:=100
.ColumnHeaders.Add Text:="Calories/portion", Width:=80
End With
End Sub
-----------------------------------------------------------------------------------------------------------------------
Private Sub tabel1()
Dim item As ListItem
Dim makanan As Integer
Dim i As Integer
ListView1.ListItems.Clear
makanan = Sheet1.Cells(Rows.Count, 2).End(xlUp).Row
For i = 5 To makanan
Set item = ListView1.ListItems.Add(Text:=Sheet1.Cells(i, 2))
item.SubItems(1) = Sheet1.Cells(i, 3)
item.SubItems(2) = Sheet1.Cells(i, 4)
Next
End Sub
--------------------------------------------------------------------------------------------------------------------------
Private Sub tabel2()
Dim item As ListItem
Dim makanan As Integer
Dim i As Integer
ListView1.ListItems.Clear
makanan = Sheet1.Cells(Rows.Count, 7).End(xlUp).Row
For i = 5 To makanan
Set item = ListView1.ListItems.Add(Text:=Sheet1.Cells(i, 7))
item.SubItems(1) = Sheet1.Cells(i, 8)
item.SubItems(2) = Sheet1.Cells(i, 9)
Next
End Sub
----------------------------------------------------------------------------------------------------------------------------------------------------
Private Sub ListView1_KeyDown(KeyCode As Integer, ByVal Shift As Integer)
Dim i As Integer
If KeyCode = vbKeyF1 Then
For i = 1 To ListView1.ListItems.Count
'untuk selected item ke-i maka
If ListView1.ListItems(i).Selected Then
'yang diselect = yg dimaksud dicopy
Range("G1") = ListView1.SelectedItem
Exit Sub
End If
Next i
End If
If KeyCode = vbKeyF2 Then
Range("G1") = ""
End If
If Range("H1") = "True" Then
Call tabel2
Else
Call tabel1
End If
End Sub
Mucho gracias,
Thanks a lot for the help
Bookmarks