The proper way to use dynamic tabpages in C# - c#

I am developing a simple software in .NET C# for blind people that includes a phonebook.
The phonebook consists of a form with tabs in it (each tab represent a group i.e. family, friends , work etc.) and in each tab a listview that will contain the contacts in that group.
The groups are of course dynamic and user made.
My question is what is considered the proper way to handle the tabs? To create a new listview for every tab or one for all of them? how to handle the different list views? should I redefine every time the characteristics of the listview for every tab?
Would appreciate an example.
Thanks.

The best way would be to have one listview (your main list view) and then a tabcontrol which will be the host for your tabs (this is called tabbed MDI interface) .
you can create separate forms for each one of your main entities (family,friend,work,etc.) and then based on the clicked item in the main list view you can open (or activate) related tab in the the main tabcontrol .

Related

C# WinForms - How to create a Properties Page like Visual Studio Project Properties

I'm trying to create a form that operates like the Visual Studio Properties page, with a list of categories (like Application, Build, Build Events etc) in a column on the left and corresponding information on the right. I'm planning to use either panels or a tabcontrol (with the tab header hidden) for the right hand side.
However, I'm unsure how best to create the column of categories on the left. Is there a standard control that provides this functionality?
Otherwise, I considered using a panel containing Buttons, or individual Panels, or a ListBox, but I don't think these would give the same look. Also, I don't want to write code if a suitable control already exists.
Ideally I would like to be able to easily disable all the categories, for example while editing a record on one page.
Having nested categories might be nice, but is not essential.
If the information on the right is not related to one another as you switch categories on the left, to create a good separation between categories I'd suggest you do the following:
Create a user control for each individual category
Split your form in two, the bar on the left and a panel on the right
The bar on the left, for the categories, can be a list of radio buttons, or links, or whatever you like. I'd suggest a TreeView since it easily support sub-categories.
As the user click on a category (by attaching a method to the corresponding even on the control used for the categories) you can remove the control from the panel, if any, and reset the control that corresponds to the selected category.

C# How to group different Form Controls together?

I am using Windows Forms.
I do only have one Frame. In this Frame I organized some Controls together. Where the Controls in one Row belong together (they form an Object). And overall I have five of those Rows, with the same Controls.
Eg.: Name , Surname, Age, Income, etc (in one Row)
There are Dropdownlists, Checkboxes, NumicUpDown, etc
I would now need to know an way to "bind" them together. The same counts for the Events. Because at the moment I would make for every different Control an Event and then distuingish them by an Number at the end of the Controls Name, which would be rather annoying. And then generate from that the Object.
What way do I have to not make dozens of Events and indicate that everything in one Row belongs together?
For grouping them together on the Form (not Frame) - put them all on one Panel.
To use the same even handler for all of them - simply subscribe to the same one. (Using the designer - select the events, and choose from the drop down. For doing this from code - just do YourControl2.EventName += YourControl1.EventName.) Note that this is not possible for every type of Control and every event. It's only possible if the events have the same signature.
You can easily create a UserControl. Right-click the project or a folder in the project and select UserControl. You can then add controls to it, in the designer, just as for Forms.
Once you have compiled the project, your UserControl will appear at the top of the toolbox and you can drag and drop it onto a form.
Like this would would create a user control representing one row, and add one of them for each row to your form. You can also add additional properties, methods and events to your user control class. They will automatically appear in the properties window.
But in your case, a DataRepeater Control for Windows Forms would be appropriate. It is part of the Visual Basic Power Packs, but just works as well in C# projects.
take all your controlls in one Panel. So You can with group more RadioButtons and they can know one for anderer. Then you can between them scwiching so you becomming what you whant.

Best way to display groups of data in one form?

I am looking to create a windows form. This form is to display groups of data separately and I was aiming to do so in the same form window rather than have multiple windows open.
For example each group of data is defined by a Job#. A user will want to review X different Job#'s at a time (Range would usually be 1-5, but could be more). I would like to have 4 dataGridViews for each Job# plus various identifying and summed data in text boxes. Initial Example Concept
I was looking into using TabPages/Tab Controls. My initial idea was to have a user click the different tabs to view the data for those jobs that they have pre-selected. However these tabs don't seem to behave like classes from what I can see. Is there perhaps a better way to go about this or some way to have the tabs act like classes? So that each tab has a Job TextBox, 4 Different DataGridViews, etc. So that I can easily create and display any number of jobs?
For example each Tab would have 4 dataGridViews, maybe 8 Text Boxes, Standardized Labels and a Standardized layout.
So would using tabs be a good idea? Using some other WinForm control?
There are at least 2 solutions here:
Create a custom Panel holding all the controls you want (TextBox, DataGridView, ...), design it so that it looks best to you. Then add each of that Panel to each of TabPage of your TabControl.
Create a new custom TabPage and add the custom TabPage to your TabControl.TabPages instead of the standard TabPage.
I think the second approach can be done if you can initialize everything using code (not by drag-n-drop) because to get the drag-n-drop supported, you may need to write a custom TabControl. So the first approach is feasible and OK. You can replace the Panel by a Form, set the Form.TopLevel = false, you can add that form to any container control. Using Form, you can benefit the easiness of drag-n-drop to design and organize your controls.
Here is a little of code which may help you figure out:
public class TabPageClient : Form {
public TabPageClient(){
InitializeComponent();
Dock = DockStyle.Fill;
TopLevel = false;
FormBorderStyle = FormBorderStyle.None;
}
//.... other code
//I think this is important
//You should define some Properties and methods to control the data flowing into and out from your TabPageClient.
//You can also support some method to add/remove the controls dynamically.
}
Take the drag-n-drop requirement into account, I think using UserControl may be better:
public class TabPageClient : UserControl {
public TabPageClient(){
InitializeComponent();
Dock = DockStyle.Fill;
}
}
For UserControl, you should place the class in a separate *.cs file, compile your project and then you can see it in the ToolBox window (at the very top). Just drag and drop it like as other controls.
Personally, I prefer grid-detail views. Something we make heavy use of in our software. The form has a SplitContainer in vertical alignment.
In the top panel, you add a list of some kind (ListBox, ListView, DataGridView...any control into which you can load a list and then react to selection).
In the bottom panel, you have yet more options. Simplistically, you could use a TableLayoutPanel and then setup rows/columns to provide whatever arrangement of embedded controls you like, such as your array of grids to display data. I suppose in keeping with your model, you'd have a single ColumnStyle and four (4) RowStyles. Then in each row, add a grid.
This way, you keep it all in one place...one "screen", if you like (no tabs to flip through). You react to the selection in the list to decide what data to display in the grids. You then just need a bit of code (a class I would hope) that interfaces between the class(es) that provide the data, and the form controls that display it (the grids).
An additional benefit here is that with the list presentation, you can have a lot more than five (5) jobs in play at any one time. In fact, with scrolling, as many as you like (not limited to the number of tabs before the display goes to pot).
Also, you would be re-using the grids. Simply refreshing the displayed data for the list item selected. You could even pre-load and cache it all if freshness is not an issue.
Also consider binding directly to data source if that's an option.

One ViewModel for multiple views in wpf mvvm

I'm working on a wpf project with mvvm pattern, I have such a scenario: My window is seperated into two parts, the first part is simple, only a textbox for users to input keywords and a button for searching with keyword. The second part is user control, by default, it's a advanced search user control, users can select different selections, such as categories, authors, each of the selection support multiple selection. After user setting the filter in the advanced search user control, click search button in the first part to search. After the searching results return, replace the advanced search user control with a result list user control.
Should I create a viewmodel contains result collection, advanced search options and used for the main window and the two user controls? Or is there any more appropriate solution?
Thanks in advance!

How to implement search for form objects?

I use c# and c++ builder, and have big application with many menus, buttons, check boxses, and also with many forms. When trying to use one of functionality of those objects I use standard user method by clicking on button, clicking on menus and choose some submenu options, etc...
But now I want to use faster method to use functionality of objects, want to create search for objects. That means if I type name of some button and press enter, that those event become same as i click on same button. I don't want to clicking on buttons, and menus anymore cause it take me too much time to find it.
So I create new form which appear on shortcut and have inside listbox that will be using for search all objects, but I don't know what code to put inside that listbox show me all object names?
How to connect listbox with all objects which is inside project?
In C#, every Control has Controls property that returns a collection of child controls. You can iterate through all the "children" of a form and add their names to your listbox. In the opposite direction, when you've got a control name, you can find it using Controls.Find() method.
For CBuilder case, refer to the following thread:
BCB : how to iterate over controls on a form?

Categories

Resources