Hi everyone!
Here is my request for help. I have several UltraNumericEditors on the same form and I want to change the same property once I click on one of the RigthButton, for ALL the NumericEditors.
So far I've tried the following code, and no luck! It only works with the caller...
Private Sub MV_EditorButtonClick(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinEditors.EditorButtonEventArgs) Handles UltraNumericEditor_MV_1.EditorButtonClick, UltraNumericEditor_MV_2.EditorButtonClick
If e.Button.Key = "Def" Thene.Button.Editor.Value = 0.05End If
Dim stateButton As EditorButton = CType(e.Button, EditorButton)
For Each ctrl As Control In Me.Controls If TypeOf (ctrl) Is UltraNumericEditor Then DirectCast(sender, UltraNumericEditor).BackColor = Color.Wheat Select Case stateButton.Text Case "Meters" stateButton.Text = "Feet" Case "Feet" stateButton.Text = "Inches" Case "Inches" stateButton.Text = "Meters" End Select Else DirectCast(sender, UltraNumericEditor).BackColor = Color.CadetBlue End IfNextEnd Sub
1) The code above won't work "as is" unless I replace "ctrl" with "sender" (???), I mean Typeof Ctrl does not recognize the UltraNumericEditor type.2) If I use "sender", then it works, but only changes the properties of the NumericEditor that was selected
What am I doing wrong?
In short, what I want is to click on the RighButton of one of the NumericEditors and change the text to ALL at once.
Thanks in advance!
Gus
If you change ctrl to sender, then the condition is always true, since sender is the control that was clicked.
You problem is that Me.Controls is only the top level controls and probably your UltraNumericEditors are in a tab page or a panel.
You need to create a recursive method like this and call it from your event:
public sub ChangeValue(control as Control)
If TypeOf(control) Is UltraNumericEditor Then
DirectCast....
End If
For Each child As Control In control.Controls
ChangeValue(child)
Next
End Sub
jct said: If you change ctrl to sender, then the condition is always true, since sender is the control that was clicked. You problem is that Me.Controls is only the top level controls and probably your UltraNumericEditors are in a tab page or a panel. You need to create a recursive method like this and call it from your event: public sub ChangeValue(control as Control) If TypeOf(control) Is UltraNumericEditor Then DirectCast.... End If For Each child As Control In control.Controls ChangeValue(child) Next End Sub
jct, thanks for the prompt answer.
Mine was just an example with the DirectCast, what I'm really interested in is the RightButton text, so I need the "e"
From your solution, how can I do that?
On the other hand, previously I used Me.UltraTabControl1.Control at no avail...
I think you can access the buttons with the ButtonsLeft and ButtonsRight properties.
Using the UltraTabControl won't help since it contains pages and each page contain the controls. The recursive way is the best way, but you can use reflection if you really want to get your hands dirty...
I've been able to perform the backcolor change in ALL NumericEditors
However I cannot change the TEXT property of the RightButton...in ALL editors! (works only for the pressed one) Dim stateButton As EditorButton = CType(e.Button, EditorButton)
For Each ctrl As Control In Me.UltraTabPageControl1.Controls If TypeOf (ctrl) Is UltraNumericEditor Then 'And ctrl.HasChildren Then DirectCast(ctrl, UltraNumericEditor).BackColor = Color.CadetBlue Select Case stateButton.Text Case "Meters/Sec" stateButton.Text = "Feet/Sec" Case "Feet/Sec" stateButton.Text = "Inches/Sec" Case "Inches/Sec" stateButton.Text = "Meters/Sec" End Select End If
Moreover, I cannot find the TEXT property! I mean I can find every other one but this.
UltraNumericEditor_MV_1.ButtonsRight.Item("Units").text = "dd" (this is of course what I expect, but doesn't work at all)
Any ideas?
Thanks!
Mike Saltzman"] Oh, sorry. The problem is that the ButtonsRight collection returns an EditorButtonBase and not all editor buttons have a text property. So you have to cast it to the appropriate type of button. So to break up the code more neatly, it looks like this: Dim une As UltraNumericEditor = DirectCast(sender, UltraNumericEditor) une.BackColor = Color.Wheat Dim eb As EditorButton = DirectCast(une.ButtonsRight("def"), EditorButton) eb.Text = "Text"
Oh, sorry. The problem is that the ButtonsRight collection returns an EditorButtonBase and not all editor buttons have a text property. So you have to cast it to the appropriate type of button.
So to break up the code more neatly, it looks like this:
Dim une As UltraNumericEditor = DirectCast(sender, UltraNumericEditor) une.BackColor = Color.Wheat Dim eb As EditorButton = DirectCast(une.ButtonsRight("def"), EditorButton) eb.Text = "Text"
Mike,
It works perfectly well.
Thanks again for a great service!
Mike Saltzman"] (DirectCast(ctrl, UltraNumericEditor)).ButtonsRight("Def").Text = "text"
(DirectCast(ctrl, UltraNumericEditor)).ButtonsRight("Def").Text = "text"
Thanks for the reply, however something is wrong in that expression.
I pasted the code and syntar error message poped-up
To be honest, I cannot find where the error is.
Additonal help would be greatly appreciated!