Гость
Целевая тема:
Создать новую тему:
Автор:
Форумы / Visual Basic [игнор отключен] [закрыт для гостей] / Можно ли в VBA у контрола ListBox подписаться на событие click? / 6 сообщений из 6, страница 1 из 1
27.01.2010, 08:52
    #36432730
Lepaj
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Можно ли в VBA у контрола ListBox подписаться на событие click?
Всем доброго времени суток!

Возник трабл. В экселе через vba динамически генерирую ListBox на форме и его заполняю. Вопрос в том, возможно ли подписаться на событие click у динамически созданного контрола? Если да то как?

Код: plaintext
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.
Private Sub UserForm_Initialize()
    
    frmReport.Caption = "Анализ поступления заказов"
    frmReport.Height =  500 
    frmReport.Width =  700 
    frmReport.Left =  50 
    frmReport.Top =  50 
    
    Set lstBox = Controls.Add("Forms.ListBox.1")
    
    With lstBox
        .Top =  50 
        .Left =  0 
        .Height =  350 
        .Width =  700 
        .ColumnCount =  2 
        .ColumnWidths = "0;100;200;"
    End With
    
    Set e3420 = New c3420
    
    Dim i As Long
    
    For i =  0  To e3420.pRecOrdersCount -  1 

        lstBox.AddItem

        lstBox.Column( 0 , i) = e3420.pGetRecID(i)
        lstBox.Column( 1 , i) = e3420.pGetRecNumber(i)
        lstBox.Column( 2 , i) = e3420.pGetRecDescription(i)

    Next i
    
    
End Sub

__________________

С уважением, Lepaj
...
Рейтинг: 0 / 0
27.01.2010, 13:20
    #36433505
Konst_One
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Можно ли в VBA у контрола ListBox подписаться на событие click?
Код: plaintext
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.
Option Explicit
' If you are adding an ActiveX control at run-time that is
' not referenced in your project, you need to declare it
' as VBControlExtender.
Dim WithEvents ctlDynamic As VBControlExtender
Dim WithEvents ctlText As VB.TextBox
Dim WithEvents ctlCommand As VB.CommandButton

Private Sub ctlCommand_Click()
   ctlText.Text = "You Clicked the Command button"
End Sub

Private Sub ctlDynamic_ObjectEvent(Info As EventInfo)
   ' test for the click event of the TreeView
   If Info.Name = "Click" Then
      ctlText.Text = "You clicked " & ctlDynamic.object.selecteditem.Text
   End If
End Sub

Private Sub Form_Load()
   Dim i As Integer
   ' Add the license for the treeview to the license collection.
   ' If the license is already in the collection you will get
   ' the run-time error number 732.
   Licenses.Add "MSComctlLib.TreeCtrl"

   ' Dynamically add a TreeView control to the form.
   ' If you want the control to be added to a different
   ' container such as a Frame or PictureBox, you use the third
   ' parameter of the Controls.Add to specify the container.
   Set ctlDynamic = Controls.Add("MSComctlLib.TreeCtrl", _
                    "myctl", Form1)
   ' set the location and size of the control.
   ctlDynamic.Move  1 ,  1 ,  2500 ,  3500 

   ' Add some nodes to the control.
   For i =  1  To  10 
      ctlDynamic.object.nodes.Add Key:="Test" & Str(i), Text:="Test" _
                                        & Str(i)
      ctlDynamic.object.nodes.Add Relative:="Test" & Str(i), _
                           Relationship:= 4 , Text:="TestChild" & Str(i)
   Next i
   
   ' Make the control visible.
   ctlDynamic.Visible = True

   ' add a textbox
   Set ctlText = Controls.Add("VB.TextBox", "ctlText1", Form1)
   ' Set the location and size of the textbox
   ctlText.Move (ctlDynamic.Left + ctlDynamic.Width +  50 ), _
                  1 ,  2500 ,  100 

   ' Change the backcolor.
   ctlText.BackColor = vbYellow

   ' Make it visible
   ctlText.Visible = True

   ' Add a CommandButton.
   Set ctlCommand = Controls.Add("VB.CommandButton", _
                    "ctlCommand1", Form1)

   ' Set the location and size of the CommandButton.
   ctlCommand.Move (ctlDynamic.Left + ctlDynamic.Width +  50 ), _
                    ctlText.Height +  50 ,  1500 ,  500 

   ' Set the caption
   ctlCommand.Caption = "Click Me"

   ' Make it visible
   ctlCommand.Visible = True
End Sub
...
Рейтинг: 0 / 0
28.01.2010, 07:44
    #36435088
Lepaj
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Можно ли в VBA у контрола ListBox подписаться на событие click?
Ругается на WithEvents :( "only valid in object module"...
__________________

С уважением, Lepaj
...
Рейтинг: 0 / 0
28.01.2010, 10:01
    #36435286
Shocker.Pro
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Можно ли в VBA у контрола ListBox подписаться на событие click?
Код должен быть расположен в модуле формы. А у вас?
...
Рейтинг: 0 / 0
28.01.2010, 10:27
    #36435382
Shamanus
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Можно ли в VBA у контрола ListBox подписаться на событие click?
Lepaj,

ищите ответ тут http://www.sql.ru/forum/actualthread.aspx?tid=727505
...
Рейтинг: 0 / 0
28.01.2010, 10:54
    #36435474
Lepaj
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Можно ли в VBA у контрола ListBox подписаться на событие click?
Shocker.ProКод должен быть расположен в модуле формы. А у вас?

Да, код был определен в модуле, а не в форме.

Всем большое спасибо! Разобрался))))))
...
Рейтинг: 0 / 0
Форумы / Visual Basic [игнор отключен] [закрыт для гостей] / Можно ли в VBA у контрола ListBox подписаться на событие click? / 6 сообщений из 6, страница 1 из 1
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]