I've created a custom form that has a couple buttons and a Text box.
This custom form is opened by a click event button I have created on a Microsoft outlook add-in that I am working on attached to a 'Ribbon'. (Not sure if this matters, no problem here).
On the windows form, The first button simply saves the contents of the text file to disk.
The other button attempts to close the form. In this buttons click event I have tried the following two lines, separate and together
this.Close(); and this.Dispose();
When I use this button or the Form exit (the 'x' located in the upper right of a windows form) I receive the follow error,
COMException was unhandled by user
Exception from HRESULT: 0x800A01A8
When this error is thrown, it takes me to the 'Connect.cs' files following method,
public void OnBeginShutdown(ref System.Array custom)
{
this.toolbarButton.Delete(System.Reflection.Missing.Value);
this.toolbarButton = null;
}
I'm not sure how to begin troubleshooting this. I have done a fair amount of research but unfortunately haven't found much. I'm sure the problem might be the fact I have created a custom form with no experience and there are some 'housekeeping' or 'best practices' that I have not done or are aware of.
Anyone have insight into this?
I'm guessing a little here but that HResult for a COMException means Object Required,
So, when you are calling CommandBarButton.Delete one of two things is wrong.
Either you have already disposed the button instance or you should be passing true or false to the Delete call.
The button shouldn't be disposed until after it has been removed from the toolbar, and when it is disposed you may need to do a Marshal.ReleaeComObject to dereference it properly.
Related
I've created a custom user control, that is essentially a custom button within my windows form app. I managed the redirect of the click event to using the following code:
Control[] customButtonControls = button.Controls.Find("buttonInUserControl", false);
Button nestedButton = (Button)customButtonControls[0];
nestedButton.Click += new System.EventHandler(this.button_click_handling_function);
I've appended this to the Window_Name.Designer.cs file below the generated code for the control with my button_click_handling_function being defined in my Window_Name.cs file.
The issue is that when I then click back to the Window_Name.cs[Design] page, I am met with an error page. I will include screen shots to better show the errors. Basically it is a super unhelpful page. It tells me that I have an index out of range error on my Array, but the stack call makes no sense.
If I try to build my Solution, I am met with NO compile errors and my program acts exactly as intended. The click event triggers the function just as before.
Thanks in Advance.
Portions of the designer code are run at design-time. The index out of range error is probably because at design-time there are no controls found yet by that Find call so the array is empty. You are not checking for 0 length so when you de-reference it you get the error.
It works at run-time because at that point the controls have been instantiated.
The secondary problem though is you should not put things into the Designer.cs files since that code is auto generated by the designer and could be regenerated at some point and your added code lost. Put that code in the Window_Name.cs after the InitializeComponent call.
I have an issue with a MMC snapin developed using C#. Using the code from Microsoft's MMC sample for an snapin using a property page I have noticed a DisconnectedContext error popping up after displaying a modal messagebox from a property page.
I can reproduce this every time, and I can "fix" it with a bit of a hack.
using the sample code for CanApplyChanges() in the property page's user control, I display a messagebox if there is a validation error:
public bool CanApplyChanges()
{
if (this.password.Text != this.passwordConfirm.Text)
{
MessageBoxParameters mbp = new MessageBoxParameters();
mbp.Text = "Passwords do not match";
userPropertyPage.ParentSheet.ShowDialog(mbp);
}
}
Commenting out this messagebox stops the error. I can change this to display the messagebox parented to the MMC console instead, so (I assume) it doesn't block the property page message pump, but obviously this allows the user to continue interacting with the page which is not the best UI.
Has anyone else seen this problem - I open the property page, cancel it, open it again, make it pop the modal messagebox (using the recommended way of displaying them) when you click the Apply button, then click cancel and re-open the page - I always get the DisconnectedContext error.
I don't do anything fancy in the constructor or RefreshData() methods of my control - I fetch simple data from an EntityFramework object and place it in a few textbox and checkbox controls.
Obviously there is a problem with the thread that show the property sheet interacting badly with the rest of the snapin, but I have no threads of my own, and there is no interaction between my control and the only place I interact with the parent property sheet is to call that ShowDialog method.
Any ideas will be welcomed at this point, as would any information leading to a successful apprehension of the bug!
I am using the Business Silverlight application. I have incorporated some MVVM into this and were off an running with it. We are using some telerik controls, mostly the ribbon control and the docking. We register all the telerik ribbon controls in the about.xaml.cs file, the method is DisplayUI - its here where we register the docking control then we register the ribbon after this. What happens is that when you click the ABOUT link it shows our first tab with buttons(perfect). when you click the HOME link next to the ABOUT link, we go back to the home page..but when you click the ABOUT link again it registers the controls again so we end up with two tabs that are the same.
Is there a way to check to see if this about.xaml.cs file has already been initialized? Im guessing that is has a handle on the first call in memory as I am able to see the first tabs rendering..
Thanks
here is the about code
public About()
{
InitializeComponent();
DisplayUI();
this.Title = ApplicationStrings.AboutPageTitle;
}
that display UI does all the work in registering the dockpanel and the ribbons. We'd like to not have the DisplayUI() called if this has already been rendered once.
If you do it by event handler can you unsubscribe from the event at the end of the method? Without seeing some code it's hard to work out what to change.
It's not the nicest way of doing it, but if this code needs to run once and only once then you could have a static boolean variable on the class set to false and when you call DisplayUI you check the value of this. If it's false you set it to true and run the method, and if it's true you just return.
In my code I am using a popup window to display extra information. I also have the ability to export the information in the main window to Excel.
The problem is, after the window pops up -> I see the info -> I close the popup window -> but if I try the export to Excel button, it throws the exception "null object referrence" (if I use a try/catch, the exception doesn't occur - but I don't get any information).
In the export function I am doing something like this:
{
//some code .... here
con.close();
session["dss"] = mydataset;
}
In the export button click event:
system.data.dataset dss = (system.data.dataset)session["dss"];
//then some work on this
I think, probably when the popup window opens it ends the execution and that's why when I come back to the main window and try the export button the values for the tables and all goes out of scope.
Also, if I refresh the main page after closing the popup window I don't have any issue and can export the data.
Can you please help me with this?
Thanks,
Rahul
How are you opening the popup window? Javascript? A link?
I think, probably when the popup
window opens it ends the execution
This can't be true, any opening of pop-ups happens client-side this can't possibly stop any execution server-side.
it throws the exception "null object
referrence"
Which object? Have you instantiated it? If so have you possibly nullified it?
if I use a try/catch, the exception
doesn't occur - but I don't get any
information
This isn't true - I expect you're just handling the exception (within your catch) so that it no longer being left unhandled.
If you can answer these questions I suspect you'll figure out the problem yourself. However I suspect you're posting back (and getting the server to provide the popup code) and by doing this you're inadvertently affecting your excel object. So direct your attention there.
I'm working on an application so i have write an dll which contain a form with some additional work and methods. so in the beginning of my program the thread launch this form (from my dll) to get some informations and then hide it and initialize some components and the application form and then show it. when the thread come the line where it define new instance of the exported form
"MyForm inputform = new MyForm();"
it throw an Exception called "Top-level control cannot be added to a control." so i don't know what to do ?!!. i tried to take the code of the form from the dll source code and put it in the main program and it works.... .but still i want to know what happen and what impede my application from run that form from my dll.
thanks.
The line that raises the error is possibly not the line you show above, but likely one of the lines that follows it. I.e., if you have something like the following:
currentControl.Controls.Add(inputForm);
it will not work and raise the error you mention.
Instead, use inputForm.Show(ownerForm) to show the form when you want it and you should be fine. A form (a top level control) cannot be added to a normal control, like a panel, a textbox or a picturebox.
Note: if the line in your post does raise the error, then inside the form initialization code lies a piece of code that raises the error, check there