I'm working on converting an old VBA project into a C# VSTO. I know a lot of the code has to go out of the window, but I was hoping to still use the layout and objects that had been embeded into the sheet. Examples of the objects include controlbuttons, labels, images, etc.
All of these persist nicely when I choose the document as a template when making a new project. I run into the problem in that I can't seem to select or reference any of these objects. For example there's a button in the middle of a sheet. If I open the sheet in VS2012, I can see the button. I can even "highlight" it but not select it. If I right-click on the button to pull up the properties, it will bring up the properties for the sheet, not the button. I can't resize them or move them around (not that I want to).
I also can't seem to reference them in code, ie ...Sheet1.ControlButton1... or ...Sheet1.OleObject(n)... will never refer to anything. If I open up the workbook directly from the solution folder and click on the same control I can see properties, and the formula bar in Excel reads =EMBED("Forms.CommandButton.1","").
I've also not been able to loop through all the OleObjects and just display their names. Clearly where ever the collection is that is storing these I can't find it.
Try the Workbook.Shapes collection
Edited as per the comments below. This works:
Globals.ThisWorkbook.Worksheets(1).OLEObjects("CommandButton1");
Related
I worked on VSTO C# Excel 2013. I tried and searched many approaches to find a way to trigger more events.
One of the important events I need is, cells formatted event (changing background color, merging cells.
Is there any way?
There is no such event. Your main events are for Workbook and Worksheet objects. Intellisense is presumably giving them all to you. If not, check out the MS reference for Worksheet events. There is a similar list for Workbook. These are also the same as the events available within the VBA editor inside Excel.
If you want to cheat and make an event, it involves watching all of the cells and detecting the change yourself using the Worksheet_SelectionChange event. See related: How to detect changes in cell format?
Note that approach will not work if you are trying to detect format changes that are effected by your code instead of the user (unless of course you are using Select in your code which would be inadvisable).
When you click on the add button in a lightswitch application, the default pop-up window will appear. Is there any way how to remove the by-default generated "Created","Created by", "Modified", "Modified By" lines? (Other than creating a custom add details window).
I am talking about these ones:
I have found this link here where the person says something about the metadata. Is it the right way to go? If yes, how do I access the metadata and where exactly do I put that code?
I am using Visual Studio 2013 and doing the app in C#.
Thanks in advance.
For anyone who would be stuck with this as well in the future - you have to right-click on the table in the server part, select "open with" and select "Automatic Editor Selector (XML)". You have to then scroll to EntityProperty and add "" attribute to it, as described in the link I posted in the original question. Then save the XML and reload the project. This will hide these fields when adding a data to this table.
Make sure to back up your project before doing so in case something goes wrong.
Just wanted to let you know what worked for me. I just brought up the table in "Server" view, selected the boarder, then went over to the properties, and unchecked the box marked "Enable Created/Modified properties" under "General". Sorry if that didn't work, I'm very new to Lightswitch myself!
I'm trying to design my C# winform application with a very generalized function to automatically go through all of the form elements and save their states/values in a text file so that I can load it later. I want it to be very generalized so that it'll be a cinch to reuse this code in future projects, as it wouldn't be heavily tied down to the specifics.
The form elements I want to save are text boxes, combo boxes, data grid views, list boxes and that's about it. I want to save their values and everything about them.
One way that I was going about it was to go through every possible form element and then detect eachs type, and then create the corresponding c# code to re-create its value ('tboxmine.value="blue elephant"'), and then writing the code to a file, so that I could load the code from the file and execute it using the CSCcompiler. My code so far doesn't seem to be working correctly and I'm having my doubts that this compiler is actually running the code inside my application (I think it's possibly creating a new thread?), and it just seems like there's probably a far more straightforward relatively standard way of doing this.
This seems a bit like the reverse "best practice" approach. If you dont't know about databinding I suggest you look into that.
Basically you create classes to represent your data and use databinding to associate controls with your objects. The controls will automatically show the right value and allow the user to change it. If the user has changed the value, your object gets automatically updated.
To save the data, you would use some kind of serialization to store your objects in a file. When loading, you let the Serializer rebuilt your class structure and (best case) you are good to go.
This is not exactly what you asked for, but I think it is something you could use well ;-)
N.B.: Not the complete state of the control is saved. e.g. in a Textbox your text would be saved but the BackColor won't.
To get you started look into this tutorial: http://www.codeproject.com/Articles/24656/A-Detailed-Data-Binding-Tutorial
I am new to VSTO and C# and have a question regarding split buttons. I am trying to create a split button "Insert Slide" Much like the default Microsoft Created button "New Slide".
If someone clicks on the button, it inserts a blank slide with my custom template (this part works fine for me). If I click the drop down, I want to see several categories (ex: Slide Group A, Slide Group B, etc). In each of those categories will be a series of slides (Slide Group A has a bunch of different slide templates). I had some pictures created for how it would like to look but I can't post pictures yet, so I will do my best to describe them. If you refer to the New Slide dropdown, I would like it to look like that.
I would like to dynamically build the menu such that all the group names are created based on the folder names in a specified directory, and so that the slides to insert are pulled from within that particular folder. TIf you refer to the New Slide dropdown, there would be headers (like "Office THeme" but with my folder names instead) and then a series of slides underneath which are all the slides within tha folder.
If someone could point me in the right direction as to what I would have to do to make this work (I don't need you to write out the code for me; if you could just give me a high level sense of what I would need to do to implement this) I would appreciate it. Also if you could recommend a VSTO resource for Powerpoint, that would be great (I have been looking all over and have found resources for everything but Powerpoint!).
Please let me know if this is unclear; I can provide the mock up pictures via email in case.
Thanks,
Dan
You can use gallery controls instead of split buttons. This control has callbacks like getItemImage, getItemLabel, GetItemCount which would help you to build your menu dynamically.
Here is an example I found which is using Excel 2007, you could follow this for PowerPoint
I found some code to help me in a project and when I first ran the code I received an error message indicating: "Visual Studio cannot start debugging because the debug target c:\path\'dirInfo.exe' is missing. Please build the project and retry, or set the OutPath and AssemblyName properties appropriately to point at the correct location for the target assembly."
Then I select OK and receive an error message indicating that partial is missing. I add partial to the code and receive 3 more error messages.
The type 'RecursiveSearchCS.Form1' already contains a definition for 'components'
does this mean I should delete this from the Form1.cs file?
Type 'RecursiveSearchCS.Form1' already defines a member called 'Dispose' with the same parameter types.
Type 'RecursiveSearchCS.Form1' already defines a member called 'InitializeComponent' with the same parameter types.
(I notice, when I comment out the InitializeComponent line and/or Dispose line, many more error messages populate in ERRORS)
By they way you can find the original code # MicrosoftSite.
Any help would be greatly appreciated.
Thank You
Just gut instinct, if you were following along and copy pasting remember one key thing:
The designer creates two files when you create a form: A "code" file, and a "designer" file. However, when microsoft (and others) release "templates", they like to merge these two files.
Just create a new .cs file and paste the code and all should be good. It's the code basically saying "in the designer, we already have this stuff". (a good way to note this is the "partial" keyword located before your Form1 declaration)
More info:
The Code file will house all your own implementations. That is click events, methods you personally override, events you bind to, etc. This is the default file when you select "View Code" from either your solution explorer or the dialog itself. Within this file is a construct that calls a "hidden" method, (InitializeComponent) that if you right click and "Go to Definition" will bring you to the next file:
The Designer file is the IDE's generated file. This takes everything you do in the designer and stores it for you. That includes new controls, location and properties of the controls, and the IDisposable implementation. The idea is to keep the "meat an potatoes" out of the way while you worry only about implementation.
Yes it sounds like you've copied the entire code which includes many things already contained within your Form in a partial class. Either remove these or remove the partial class and partial class declaration from your Form to get rid of these errors
I went to the Microsoft site to see what you did. The site shows code for an entire "one file" solution. We've all agreed that Visual Studio creates multi-file solutions, so you're duplicating code.
I don't know if the current answers/comments have helped you get this sample code working, so I thought I'd add my share. I was able to get this sample working by doing the following:
First, where the sample code at the Microsoft site shows declarations for button, textbox, labels, and combobox, rather than attempting to copy that portion, I simply used the toolbox and dragged a button, the labels, the textbox, and the combobox from the toolbox to my form.
You'll probably want to arrange these to your liking.
This process created my form correctly with the appropriate objects on it. All I had to do was use the properties window for each object and rename them according to what they were named in the sample. For example, my new button was originally button1, but I renamed it to btnSearch just as it is named in the Microsoft sample.
I noticed that the Microsoft sample has an established event handler setup for the Form1_load() event. I created this same event in my form by clicking the form in the designer, clicking properties, clicking on the Events button in that properties, and double-clicking the "Load" event. This automatically generated the appropriate code.
In a similar way, I had to create the btnSearch_Click() event. I did this by simply double-clicking the button in the designer.
After that, all I had to do was manually copy and paste from the specific sections of the sample to my code -- fill in the Form1_Load() event with what was in the sample. Copy the DirSearch() method over. Fill in the btnSearch_Click() event. That was it.
I hope this helps solve the overall issue and gives you more insight into how you can avoid these problems in the future.
You have duplicated functionality in the classes, you have a file that was automatically generated with that functionality already in it.