PDA

View Full Version : [SOLVED] Handle to ribbon controls



ameyav
03-05-2010, 03:08 AM
Hi,

I have made a new excel Ribbon using the RibbonX Visual Designer with some buttons and checkboxes on it.

I have set the id's for each of the buttons (say B1, B2) and the checkboxes (say CB1, CB2, CB3)

I have registered an onaction callback for the button B1. In the B1 button call back code i need to check the status of the check boxes (whether checked or unchecked), however i am not able to figure out how i can get a reference/handle to the check boxes from within the callback code for the button.

Please let me know if i need to provide more info.

Thanks!

Andy Pope
03-05-2010, 06:04 AM
Keep a track of the checkbox states in an array.

In this example the 3 checkboxes all use the same OnAction callback.



Private m_blnCBoxesState(1 To 3) As Boolean
Public Sub Button1_onAction(control As IRibbonControl)
'
' Code for onAction callback. Ribbon control button
'
MsgBox m_blnCBoxesState(1) & vbLf & m_blnCBoxesState(2) & vbLf & m_blnCBoxesState(3)

End Sub
Public Sub Checkbox1_onAction(control As IRibbonControl, pressed As Boolean)
'
' Code for onAction callback. Ribbon control checkBox
'
If control.ID = "Checkbox1" Then
m_blnCBoxesState(1) = pressed
ElseIf control.ID = "Checkbox2" Then
m_blnCBoxesState(2) = pressed
ElseIf control.ID = "Checkbox3" Then
m_blnCBoxesState(3) = pressed
End If

End Sub

ameyav
03-05-2010, 06:44 AM
Thats just perfect, not to sound too bothersome, any strategies to get the Text from a text box control on a ribbon when a onAction is called for a button?

Help appreciated!
Thanks!

Andy Pope
03-05-2010, 07:25 AM
Just use the same approach.
The editboxes text is stored in a variable



Private m_blnCBoxesState(1 To 3) As Boolean
Private m_strTxt As String
Public Sub Editbox1_onChange(control As IRibbonControl, Text As String)
'
' Code for onChange callback. Ribbon control editBox
'
m_strTxt = Text
End Sub
Public Sub Button1_onAction(control As IRibbonControl)
'
' Code for onAction callback. Ribbon control button
'
MsgBox m_blnCBoxesState(1) & vbLf & m_blnCBoxesState(2) & vbLf & m_blnCBoxesState(3) & vbLf & m_strTxt

End Sub
Public Sub Checkbox1_onAction(control As IRibbonControl, pressed As Boolean)
'
' Code for onAction callback. Ribbon control checkBox
'
If control.ID = "Checkbox1" Then
m_blnCBoxesState(1) = pressed
ElseIf control.ID = "Checkbox2" Then
m_blnCBoxesState(2) = pressed
ElseIf control.ID = "Checkbox3" Then
m_blnCBoxesState(3) = pressed
End If

End Sub

realquo
06-11-2010, 05:08 AM
Andy, thanks for your code, I was getting mad with the Edit Box (how to find that the callback needs the text as needed parameter??). Thanks again! RQ