building the RIBBON dynamically: e.OriginalSource is no longer of type: RibbonButton - command

I want to build my RIBBON-buttons dynamically. Every click on a RIBBON-button must result in opening an usercontrol. The command attached to the button is the same for all buttons.
In the executed-procedure I need the RibbonButton that activated the action.
the "executed" Command looks like this:
private void ExecTmp(object sender, ExecutedRoutedEventArgs e)
{
RibbonButton btn = e.OriginalSource as RibbonButton;
Console.WriteLine("===========e.Orig: " + e.OriginalSource.ToString());
// do something with 'btn'
}
Now, the strange thing is that it works, as long as focus does not leave the Ribbon.
If I enter a userControl on a tab (a textBlock or something) and then click on a ribbonButton again, I no longer have access to the RibbonButton. I can see on my console, that the reason for this is that e.originalSource is no longer a RibbonButton but a textBox. Output on my console looks like this:
===========e.Orig: Microsoft.Windows.Controls.Ribbon.RibbonButton
===========e.Orig: System.Windows.Controls.TextBox: 0
===========e.Orig: System.Windows.Controls.TextBox: 0
===========e.Orig: System.Windows.Controls.TextBox: 0
In the debugger I can see that if I open a tabControl, click on a combobox in the tabControl and then on the RibbonButton, e.Source points to the opened tabControl and e.OriginalSource points to the ComboBox. Isn't this strange?
Can somebody explain this ?

I'm a bit late for this question :) But anyway, hope my answer will be useful for someone else.
Set FocusManager.IsFocusScope="False" for Ribbon control. This will cause e.OriginalSource to contain RibbonButton, not TextBox.

Related

Unity UI : How to reenable a dropdown after its panel was deactivated and then reactivated?

I am new to Unity, so this is probably a dumb question but here goes:
I have a Unity app; it has several scenes. One of those scenes has a Canvas upon which there are several overlapping Panels. On one of the Panels (PanelA), there is a Dropdown. When the app first runs PanelA is active and on top by default and the dropdown works fine. But after I deactivate PanelA with a C# call to
panelA.SetActive(false);// hides the panel
and then later reactivate it like so:
panelA.SetActive(true); // redisplays the panel
The dropdown no longer displays its list of option when clicked on. The dropdown is still there and still shows its first option "None" and when clicked on the drop-down changes color to indicate that it was touched, but the dropdown does not drop down its list of options.
What am I missing? Why doesn't the dropdown show the list of options?
Thanks
Windows 10 Pro v1709, unity 2017.1.1f1 Personal
My hierarchy is like so, PanelB is the panel that gets set active after PanelA is inactivated:
The script called when the dropdowns option is selected is called like so in Start():
PickDropDown.onValueChanged.AddListener(delegate {
myDropdownValueChangedHandler(PickDropDown);
});
and the called function is:
private void myDropdownValueChangedHandler(Dropdown target) {
Debug.Log("selected: "+target.value);
stage = 0;
currentval = PickDropDown.options [PickDropDown.value].text;
advice.text = "";
title.text = currentval;
if (currentval != NONE) {
advice.text = "You chose to do "+currentval;
nextVal();
}
}
void newVal(){
Debug.Log("newVal " );
PanelA.SetActive (true);
PanelB.SetActive (false);
Debug.Log("options count="+ PickDropDown.options.Count );
}
void nextVal(){
Debug.Log("nextSet " );
PanelB.SetActive (true);
/*** next line shows the answer to my problem - from killer_mech **/
Destroy(PickDropDown.transform.Find("Dropdown List").gameObject);
/***************************************************************/
PanelA.SetActive (false);
}
Yes, this is a bug in unity. I can reproduce this now. This is happening because Unity is creating a game Object called "Dropdown List" inside dropdown which should get destroyed after the closing. But I have noticed a slight delay is happening while destroying(I used editor debug mode for this). When you set the game object active flag as false, it somehow stops the destroy object and results in object Dropdown List staying there so next time when you try to interact with it the object will still present. You will also notice a white box below the Dropdown list after this which indicates the dropdown list still is present.
For the solution what I did was just before I was about to turn my gameobject off I used
Destroy(PickDropDown.transform.Find("Dropdown List").gameObject);
Destroying this object solves the problem. I know this is not a good way to do it, but I checked whether any references to options are destroyed while destroying this which resulted in no error for me. And Dropdown creates new "Dropdown List" gameobject. So it is safe to assume that destroying is OK. Well not sure if any other good solution for this is out there but for now you can use this.
Note: I have tested this bug with Panel, Empty Gameobject as parent and finally with Dropdown
This shows what is happening inside the drop-down. 1) During No popup 2) During Open 3)After setactive off before the child is destroyed.

tabcontrol page not updated

In my winfom program I have a function that change the tabpage when I hit a key.
On tabcontrol indexchanged I check for some parametre and if they are not correct I change the tabpage to the first tab.
If I click on the page with the mouse the tabpage changed to the first tab with the correct content.
If I click a key and run this code "tcOrdre.SelectedTab = tpOrdre;" it changes the tab back to the first but still showing the content of the selected one.
In SelectedIndexChanged is use this code:
MessageBox.Show("Der skal vælges en ordre først"); // Show a messagebox
tcOrdre.SelectedTab = tpOrdreListe; // change tap to first
If I use the mouse then SelectIndexChanged get called when I run:
tcOrdre.SelectedTab = tpOrdreListe; // change tap to first
the SelectedIndexChanged function is called again and the content is okay.
But if I use the key to change index the SelectedIndexChanged does not get called Again and the content never change. Only the tab in the top change to the first one.
I hope someone can help me.
I found the solution.
All I have to do is call this line.
this.BeginInvoke(new Action(() => tcOrdre.SelectTab(0)));
and not tcOrdre.SelectedTab = tpOrdreListe;
And everything Works fine.

Text Editor in eclipse plugin is not properly executed

I have created multipage HTML editor in which one tab has text editor. I have set the global action handler to the action bar for undo / redo actions in the source editor. Whenever I am adding something in the source editor then undo it, it is not returning the same code in the first attempt. It is completing in the second attempt. Can anyone help me to solve this issue.
In the main editor override the setFocus() method and in this method call the following method of source editor.
public void setUndoRedoActionHandlers() {
final IActionBars actionBars = getEditorSite().getActionBars();
actionBars.setGlobalActionHandler(ActionFactory.UNDO.getId(),
mUndoAction);
actionBars.setGlobalActionHandler(ActionFactory.REDO.getId(),
mRedoAction);
actionBars.setGlobalActionHandler(ActionFactory.DELETE.getId(),
mDeleteAction);
actionBars.setGlobalActionHandler(
ITextEditorActionConstants.DELETE_LINE, mDeleteLineAction);
actionBars.updateActionBars();
}
Thanks
Are you sure that you set global actions by overriding setFocus()? Look at this : https://wiki.eclipse.org/FAQ_How_do_I_enable_global_actions_such_as_Cut,_Paste,_and_Print_in_my_editor%3F
It says they need to be set inside method setActiveEditor()
The reason I guess why you are seeing it working second time is - When the first time you click your editor gets focus and setFocus is called and only then the global actions are set. Then second time it will work because the actions are now set.

How do I set size of colums in a table subform datasheet view in MS Access

I have a subform bugging me. The mainform contains buttons etc. Everytime the user close/open the form, the columns width is reset to whatever the table likes. If i open the table directly, the size is as i want. If i change it in the subform, it is not saved. (See screendump)
I would like "Phase" to stay about 2 cm width. I can enter the subform and edit the "Width" but that is only applied to the other views.
I hope you can help, Emil.
I realize this post is almost 2 years old, but I ran into the same problem and came across this post.
I am running MS Access 2013 on Windows 7 Ultimate. I did not find the solutions offered here to work for me, so, I set out to find something that would work for me before I went to VBA code. (Incidentally, I appreciate the link offered by #Patrick_Honorez in his comment on the original post because that was going to be my fall-back solution.)
Anyway, here is what worked for me and I hope perhaps it will work for others as well:
Open the parent form.
In the subform, right-click the column header
for the column for which you wish to adjust the width.
Select the “Field Width” item from the context menu.
In the “Column Width” dialog that appears in step 3, enter the desired column width in points, or, use the [Best Fit] button. Then click the [OK] button to close the dialog and return to the form.
Right-click the parent form’s border to bring up the parent form’s context menu. Click the “Save” item in the context menu.
Now close the parent form.
The next time the form is loaded, the column widths should be as set it step 4 above--at least they are for my setup.
I see this post is quite old and OP must have figured someway to tackle the issue. I came across same issue today and found solution on this link.
For anybody else having same issue, use following code (I modified the code a little because original code from the above mentioned post saves column width of only text boxes but my form has combo boxes too, column width of which was not getting saved) in close and open events of your subform and then open main form in Form View and then manually select desired widths either by mouse, by entering column width value or using best fit. Save the form and reopen to check results. That's it.
Private Sub Form_Close()
Dim ctrl As Control
For Each ctrl In Me.Controls
If (ctrl.ControlType = acTextBox Or ctrl.ControlType = acComboBox) Then
SaveSetting "propertiesDBS", Me.Name, ctrl.Name, ctrl.ColumnWidth
End If
Next
End Sub
Private Sub Form_Open(Cancel As Integer)
Dim ctrl As Control
Dim frm As Form
Dim w As Long
For Each ctrl In Me.Controls
If (ctrl.ControlType = acTextBox Or ctrl.ControlType = acComboBox) Then
w = GetSetting("propertiesDBS", Me.Name, ctrl.Name, 0)
If w <> 0 Then ctrl.ColumnWidth = w
End If
Next
End Sub
I know this is late to the party and most likely going to be the last comment anyone reads, but this can be done quite simply in MS Access 2016 - by someone like myself who has no more than 4 days experience in databasing overall and no experience with writing custom Macro's or VB Script (using only what is native to MS Access).
Here's how I did it.
Scenario - Split Form (Form + Datasheet).
Extra Recommendations:
It pays to be across all properties of every object type in your database, as a change in a field property can cause unpredictable erratic effects, which take ages to figure out why it happened and how to stop it from happening again, whilst delivering your desired outcome.
Me.Requery in your VBA script after every necessary event and also in your main form (generally the 'After Update' event is used most), and be wary that too many Me.Requery's (in unnecessary events) can also be detrimental - so too much of a good thing can be a bad thing.
Bottom Line Up Front - Modify the format of your query that is to be exported/printed.
In 'Design View' of the query you are concerned with, ensure that the fields are in the order you need them outputted in first as this is exactly how the macro will present them for export/print (example could be "Australia" then "Northern Territory" then "Town's In The Northern Half Of The State" then "Darwin" then "Suburbs In The Northern Half Of City").
Switch to 'DataSheet View' in the same query and use the top left folded over triangle looking thingy to highlight the entire data set then right click that same triangle to present an options menu. Select 'Row Height' and type in "15" (default row height in Excel).
Deselect the entire spreadsheet and this time select every column (left click the left most column, hold shift button, scroll over to the right to the far end of the data set and click the last column) and then right click one of the highlighted columns to present another menu. Select 'Field Width' and within that new pop-up menu select 'Best Fit' and then 'OK'.
(Optional - not sure if this helps or hinders but I did it for my purpose) With the columns still selected right click one of the highlighted columns again and select 'Freeze Fields'.
My scenario had buttons with macros configured to run filtered reports so I was able to check this by simply clicking any of those buttons and seeing the report formatting, which it held true to the work I had just done. I exported using another button with a macro that exports to Excel with 'Print Formatting' selected (my main form also had the datasheet view as the only thing that could be printed and was also set in 'Print' formatting.
The Excel spreadsheet opened with all row heights and column widths in a way that I could read every field/record with perfect ease and without extra modification.
This also worked for cascaded combo boxes, with the export only outputting the 'drilled down/filtered' datasheet records, in a format that required no further modifications.
Hope this helps someone, as its saved my hide! :)
Open the Main form in Design. Go to the SubForm. Click on the square at the top left of the SubForm and select 'Properties'. Right-Click the control 'Phase' and click 'Properties'.Click the 'Format' tab and select 'Width'. What do you see there? That should control the widht of control 'Phase' unless you have some overriding coding elsewhere. Input the size you want and see what happens.
Use continuous forms instead. It gives you complete control over how your subform displays.
If you open your subform directly, your property sheet menu should display automatically if the default view is "Datasheet." Click on "All" and change the "Auto Resize" property to "No." This should solve the issue and avoid the need for VBA.
This only works when you open the subform separately. So if you want the changes to be reflected within your main form, you'll have to close it and switch back and forth.
Super annoying by default.
It seems to work as one would expect of you set the view mode to layout view. Drag column widths as needed and save. Go back to form view and it works. It's really dumb it doesn't work the same way in form view our design view.
In Access 365, open main form, right-click sub-form datasheet columns that need width adjustment, use the Field Width to adjust, click on border of main form to select Layout view, and save changes.
Open subform in datasheet view (by double click on subform in the left pannel)
Resize columns as you want by dragging or by right-click the column header for the column for which you wish to adjust the width and select the “Field Width” item from the context menu.
Right-click the subform border to bring up the context menu. Click the “Save” item in the context menu.
Either open the Main Form in Layout View or directly open your Subform in Datasheet View. Right Click on the Field Header, select Field Width, and enter the desired width. Save. Bewm.
My solution (Access 2016) was to create the main & subform, recreate the subform on its own using form wizard and set it up the way I want it, rename the original subform to something else, and finally rename the recreated subform to the original form name. Open the main form and the subform should be laid out the way you want it. You can then delete the original subform you renamed.

Dynamically reload a table in a form programatically

I have a form in Dynamics AX which displays a table of two columns in a grid. I also have a button on the form. I am overriding the clicked method of the button to update the Address field of the table. For example, here's my X++ code:
void clicked()
{
AddressTable addr;
ttsBegin;
select forUpdate addr where addr.addressID == 1;
addr.Address = "new address";
addr.update();
ttsCommit;
super();
// reload table here
}
What I would like to do is to add a code to the clicked function which will reload (re-select) the updated records and show them in the form without a need of reopening the window or refreshing it using F5 (for example).
I went through forums and AX documentation and found a few methods like refresh and reread, but they are FormDataSource class methods and I failed to make it happen inside the clicked handler above.
So, what I really want to accomplish programaticallyis what F5 does behind the scenes when clicked on an open form.
Maybe just addressTable_ds.research(true); will do the job.
See also Refresh Issue on the form when the dialog closes.