VSTO AddIn Form Showing a Dictionary - c#

I want to display a dictionary on a form in an Outlook 2013 AddIn with VSTO in C#.
Actually I want to display two dictionaries, maybe a large dialog with 2 listbox or something to list the key value pairs, or two tabs each with a listbox or something to display one dict and one tab to display the other dict.
Anyone know the best way to accomplish this? I've tried all the methods I found online and none seem to work. I'm a bit stuck. Anyone know a good way to take achieve this? The dictionaries are created during the AddIn startup within the OutlookRibbon class. I can make them accessible from the outside if need be by making public properties if needed or just make the variables public.
This isn't part of my question, but I want to eventually perform CRUD operations on the dictionaries. If there is a better way to accomplish this than a form with buttons that will manually perform the operatins, I'm all ears. I am not using a database, this is a small addin and I need these dicts to be stored somewhere local and small. They have about 15-25 entries each so they are not big.
Any advice and short examples would be much appreciated and a huge help.
Thanks

I want to display a dictionary on a form in an Outlook 2013 AddIn with VSTO in C#.
I'd suggest using Outlook form regions in that case. See Creating Outlook Form Regions in MSDN for more information. It is up to you which controls to use on the form (depends on the business logic). .Net framework allows to use a lot of third party controls.
They have about 15-25 entries each so they are not big.
If you don't plan to store a huge amount of entries you may consider storing them in JSON or XML files.

Related

Visual Studio - Modular control groups in a Form

In my project I have the need to create a Form with 16 identical replicas of the same controls. So far I've managed to do this by just copying and pasting the controls and renaming them one by one, however this is becoming really inefficient and I feel like there must be a better method to handle this situation.
Down below there is an example of what I'm talking about: every line has the same controls that are handled exactly the same, have the same Items and only interact with each other within the same line.
Is there a way to create a modular group of controls that I can replicate and handle with a simple incremental index? The best would be if modifiying the original one would affect every copy of it!
I'm using Visual Studio Express 2013 for Windows Desktop and C# as programming language.
This kind of data calls for a DataGridView Control. It supports text, checkbox and combobox "out of the box", and you can add support for Numeric Up/Down Cell as described here: https://msdn.microsoft.com/en-us/library/aa730881%28v=vs.80%29.aspx
Creating a custom control as Johnny Mopp suggested (in the comments) was the best solution for my problem.

Reducing Complexities in Single form Application

I've created a win form application which consist of a single form. We have 8 tabs to access the modules of application.
The problem is we are a team of 4 who works on this project. But since it is a single form application, only one person can use the file at a time. Is there anyother way to build application with more than one file?
Please provide some solution.
Firstly, you should probably have a separate UserControl per tab. That will give you 8 files (at least) since you have 8 tabs.
Secondly, you should be using a Model-View-Controller style architecture for Windows Forms applications. That will give you at least one controller, but likely you will have one controller per UserControl (i.e. per tab). You might even have an overall controller that manages the per-tab controllers.
You might only have one data model for the entire app, or you might have one data model per UserControl (tab).
If you did all that, you'd have a few more source files.
However, it's actually difficult to say without knowing anything about your app.
Try using user controls to make each tab modular.
Figure out what are the parameters that each tab accepts and that it exposes and then create user controls that have that behavior.
Here are couple resources to get you started
http://msdn.microsoft.com/en-us/library/aa302342.aspx
User Control vs. Windows Form
User Controls in Windows Forms - Anything similar to ASP.NET User Controls?
Even if this is a giant ball of wax, your source control tools are shoddy and breaking it up into separate classes is hard to do, you can still take advantage of a Form class being a partial class. Which means that you can spread the code over any number of source code files, not just the two files that the designer creates. So a logical organization is to move code that belongs to a particular tab in its own partial class with the same form class name and its own source code file. Some cut+paste required however when you add event handlers with the designer.
Have you considered using MDI?
MSDN Working with MDI...
Examples are in VB.Net but I'm sure it will be easy to use C# if you really want to - I'm not sure why, but... :)

Dynamically creating user inputs

I'm programming in C# with Windows Visual C# 2010 Express.
My goal is to create a form that shows a single row of Textbox inputs at initialization, but after the information has been filled out, have the program create a second row to allow for the user to enter another row of information. I also don't know the limit to how many of these rows will be needed, hence the hope to dynamically create them. I want this program to be versatile enough to create an infinite (sort of) number of TextBoxes/Buttons/Labels/etc.
Everything that I've seen so far is web-based (C# in ASP.Net). I want to make a program that has this functionality instead. Any thoughts or insights? I don't know if this is possible.
Use a DataGridView with a TextBoxColumn and use a BindingSource to attach it to a List<string>.

Breaking code into manageable chunks

I have a Windows Forms application written in C# and one of the forms has an enourmous amount of code with it. I have made extensive use of classes to keep the forms code to a minimum, but because the form has a number of tab pages and hundreds of controls and datagrids, etc., the code on the form itself is still extensive.
Is there any way to break this code into more manageable and smaller items, perhaps one item in the solution for each tab page, whilst keeping all the code in the same scope?
If your looking for better readability and maintainance without moving the code around too much, you could use:
#region Tab 1
#region Variables
#endregion
#region Properties
#endregion
#region Methods
#endregion
#endregion
This would allow you to minimise parts of the code you are not interested in while making changes to a certain tab. It's not perfect, but it may help.
If you are looking for the restructuring the code and its framework then you must be aware of the SOLID principles. A good article for it is S.O.L.I.D. Software Development, One Step at a Time.
You could use Partial Classes to split code into several cs files, but I really don't see to much benefit in that, only solution is to do full refactoring and remove code that has nothing to do with UI into separate classes.
You basically need to refactor. This is a common problem with classic Windows Forms applications, so you have to be disciplined and decide how to tidy up. It's not going to be an instantaneous fix.
Lookup MVC/MVP, even MVVM and learn how others break their code up. From there you can introduce a tiered architecture that suits you.
However, you aren't alone. The refactoring tools in Visual Studio or even better in ReSharper can automate a lot of the copy paste cycle, eliminating errors and automatically keeping variable names, etc. in sync.
Code which belongs to the presentation layer of a user control you can put into a class which extends the control.
Extract the code out of each tab and create a user control to contain the code for each tab. (you could even inherit from TabPage and add these to the form on init)
Then the user controls can be added in to each tab and should reduce code significantly.
The grids etc can also be turned in to user controls exposing the minimum number of methods and properties required for the other controls to access.
If you are defining form controls over and over, just create a new instance of them on your other tab.
Create getter and setter to access this.
But really, there is no problem with having lots of code for form controls, its just the way it is I think. I thought Visual Studio was supposed to generate all this for you using Windows Forms?
I personally have trouble with regions. It sometimes throws the editor and you need to close and re-open the file to reset it (I am working with Boo in SharpDevelop, and it may be specific to that), so for large forms with tabs I tend to use partial classes.
A neat trick you can do in Visual Studio/SharpDevelop file explorer is to drag the file for the partial class onto the main file for the class, so they all sit nested under MainForm (next to the .designer and .resx files) which just keeps things neater.

What are things/points to keep in mind while developing a reusable custom control?

Windows Form (in C#) - I need to create a custom listbox control for the following requirement:
There is a listbox with a long list of items. I want the user to be able to click in the list, and then start typing and have it automatically take them to the matching item (I call this "type ahead"). It needs to be able to do this for as many characters as they type that have a match.
This control should be really reusable without much changes.
What are things/points I should keep in mind while developing a reusable custom control? (if you provide a good pattern as a sample... will be more helpful)
In Real World scenario the first decision should be buy vs build. if your application is a serious one and not just for hobby and there is budget for it I would check some of those great controls collections like DevExpress or Telerik for WinForms. You would need a grid as well at some point, eventually, and surely your custom or framework one cannot compete theirs.
I refer to those libraries because i believe they already have a listbox with autocomplete as you described in your requirements. check the online demos on their websites...

Categories