Me.Close() not working in VB with WPF - wpf

I'm using VB with WPF and I am trying to close an application... the code I usually use ( Me.Close() ) is not working this time. The error it gave me was BC30545.. but it didn't help me understand the issue. Thanks for any solutions you all respond with.

The error code BC30545 corresponds with this message:
Property access must assign to the property or use it's value
Make sure you don't have another method/property/control with the same name (For example, a button on your form called "Close"
In the case of this example, you'd rename to something like CloseBtn so that it doesn't interfere.

Related

Close method not working in Office

Im trying to use Microsoft.Office.Interop.Word._Document.Close() in a .net 3.5 windows form app.
No matter how much I search here and on Google I cannot find the correct parameters to put in the Close method.
I am using version 14.0.0.0 of Microsoft.Office.Interop.Word and I would like to close the document without saving and ideally ensure that the application can isolate the document thread so that users can still open word documents outside the running application.
See the Close method of the Document class described in MSDN. If you need to omit the parameter and use the default value - pass the Type.Missing parameter.
Try this:
object doNotSaveChanges = Word.WdSaveOptions.wdDoNotSaveChanges;
object missing = System.Reflection.Missing.Value;
_Document.Close(ref doNotSaveChanges, ref missing, ref missing);
This is the source
I'm not sure if you'll need the middle line or not. It's not from the original source it's from here

drag and drop Outlook attachment from Outlook in to a WPF datagrid

I saw this code ealier about drag and dropping attachment files (http://www.codeproject.com/Articles/28209/Outlook-Drag-and-Drop-in-C) from Outlook into Windows Form and it works fine in windows Forms, but I can't seem to make it work with WPF.
I tried to simply change System.windows.form.IDataObject to System.Windows.IDataObject but it doesn't work (as I should have guessed).
I also simply tried to get the content of the e.Data FileContents but always get errors (which seems to be the case to everyone when I check on the web).
Did anyone ever did drag and dropping attachment from Outlook to WPF ? I am at a complete loss.
Edit : I am not trying to get file from a Windows Explorer windows ( I do but I know how to). It's really the whole getting attachment from Outlook directly that doesn't work . I am fully aware too that I could simple take the file from outlook into a temp folder and then drop it into my program, but I would like to avoid this unncessary step if possible.
so in the end I was able to find out a link where someone did exactly that :
https://gist.github.com/MattyBoy4444/521547
For those who wonders. Here is what I did exactly.
Create a new project in C# (my code is in VB) and add the code to it
Reference the new project in my main project to be able to use it
In my drop Event, check whether or not I had the "FileGroupDescriptorW" object in the drop data and called the method if I do to retrieve the files.
Here is the complete code
If obj.GetDataPresent("FileGroupDescriptorW") Then 'Outlook
Dim oOutLookObj As New Helpers.OutlookDataObject(e.Data)
Dim StrFiles() As String = oOutLookObj.GetData("FileGroupDescriptorW")
Dim contentStream() As System.IO.MemoryStream = oOutLookObj.GetData("FileContents")
' Do intended work...
End if
The names of the files are in StrFiles and the content are found in the streams. Both have the same array size and are order correctly.

How to show Excel ribbon when it is embedded in Webbrowser

Using the suggestion from here, I managed to embed Excel 2007 in my WPF WebBrowser control. However, the ribbon doesn't show up. I tried various techniques and nothing makes it work.
I tried this:
_application.ExecuteExcel4Macro("SHOW.TOOLBAR(\"Ribbon\",True)");
I also tried to run this from a macro after the Excel workbook is constructed,
Sub hide_ribbon()
Application.ExecuteExcel4Macro ("Show.Toolbar(""Ribbon"", False)")
End Sub
Sub show_ribbon()
Application.ExecuteExcel4Macro ("Show.Toolbar(""Ribbon"", True)")
End Sub
but it doesn't work either, although the same macro works fine in native Excel.
Also tried this:
CommandBar cb = _workbook.CommandBars["Standard"];
cb.Visible = true;
cb.Enabled = true;
cb.Position = MsoBarPosition.msoBarTop;
Or tried changing "Standard" to "Ribbon", but nothing works.
Ctrl+F1 doesn't work either.
Anybody got a clue?
It took me over 3 weeks of digging to work this out - even then I still need to test that it all works as expected.
As you already know the ribbon is automatically hidden when embedding Excel and that you need to 'toggle' it back on again by sending an OLE command.
I assume that you are uisng the SHDocVw library wrapped in with an ActiveX container, in the manner described in the knowledge base article is article http://support.microsoft.com/kb/304662 and that you have set up the appropriate registry entries to get the browser to display Excel docs (I am sure that you must have done if all you are missing is the Ribbon).
I am using C#, so you may have to mess about a bit in VBA.
The article entitled "WebOCHostVB.exe Hosts the WebBrowser Control in Visual Basic .NET" in the MS support knowledge base looks promising however, the URL is "support.microsoft.com/kb/311303"
Once the document is opened, call ExecWB on the browser as follows :
object omissing = System.Reflection.Missing.Value ;
this.axExcelWebBrowser1.ExecWB(SHDocVw.OLECMDID.OLECMDID_HIDETOOLBARS,
SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER,
ref omissing, ref omissing);
This should toggle the Ribbon state - as it is off when we start, a single call should make it display. Doing this again should hide it - though I have not tried.
The constants are in the shdocvw.dll that you must reference from your project. Even though these are integer enumerations, I could not redefine them locally and get things to work.
You can find other OLE commands, that might also be useful for your application, here :
http://msdn.microsoft.com/en-us/library/ms691264%28v=VS.85%29.aspx
I don't know why this has to be so difficult, or why the behaviour of Excel is not consistent with that of Word.
Hope this helps.

Sharing Linq to SQL DataContext between WP7.1 and WPF apps?

I have built a WP7.1 application that uses a local database. I used sqlmetal to generate the data context as per this article. http://blogs.microsoft.co.il/blogs/alex_golesh/archive/2011/05/24/windows-phone-mango-what-s-new-local-database-part-1-of-8.aspx
This works as expected using this in the ViewModel.
context = new BirdsnBflysDC("DataSource='isostore:BirdsnBflys.sdf'");`
I am now attempting to "share" the Model and ViewModel code with a WPF application. Initially I added the appropriate files as a link to the WPF project. Creating an instance of the context didn't work so as a test I have added just the data context code to a WPF project and attempt to create an instance of the context in the Loaded event handler as follows.
BirdsnBflysDC context = new BirdsnBflysDC("DataSource='C:\BirdsnBflys.sdf'");
DataContext = context;
The code actually has the complete path to the database. When I step through this in the debugger the context initialization in the data context quits running as if there was an exception, the second line of code above is never reached and the WPF window is shown as if things completed correctly.
I've tried several variation in the DataSource string including "|DataDirectory|\\BirdsnBflys.sdf" all with the same result.
Any suggestions as where to go with this? How to figure out what isn't working correctly?
Thanks,
Dave
The problem is that what is expected in the connection string is different for the two environments.
WP7 works with this.
context = new BirdsnBflysDC("DataSource='isostore:BirdsnBflys.sdf'");
WPF works with this.
context = new BirdsnBflysDC("|DataDirectory|\BirdsnBflys.sdf");
If you give WPF a file name that isn't there you get no error information, the instantiation of the data context fails quietly and any additional code does not get executed.
Dave
Did you remove the 2 methods from the generated cs file? I mean the methods unsupported by mango.
public ExternalDB(System.Data.IDbConnection connection) :
base(connection, mappingSource)
{
OnCreated();
}
public ExternalDB(System.Data.IDbConnection connection,
System.Data.Linq.Mapping.MappingSource mappingSource) :
base(connection, mappingSource)
{
OnCreated();
}
I am not sure about this, but they might be needed for wpf.
Hope this helps.

DataBinding error -DataGridView in Winforms

I'm new to VB.NET, Windows Application, and DataGridView.
This is a very basic error which I'm suffering now. I have a stored procedure to retrieve data from the database. I stored those data in a DataSet and tried to view it in a DataGridView. I used this code for databinding which is throwing the error:
DataGridView1.DataSource=ds
DataGridView1.DataBindings()
The second line in the code is throwing an error:
Property access must assign to the property or use its value.
How can I solve this?
There is no DataGridView1.DataBindings() when dealing with Winforms, it's practical in Webforms.
Just remove the last line and leave the following:
DataGridView1.DataSource=ds
Perhaps you meant:
DataGridView1.DataSource=ds
DataGridView1.DataBind()
EDIT :
You haven't provided enough code to check that everything is in place, but I suggest you work your way through this: http://msdn.microsoft.com/en-us/library/fbk67b6z.aspx
use DataGridView1.Databind()
hope that helped...

Resources