adding a control to tabs generated dynamically in tabcontrol in C# .net - c#

I am new to C# .NET.
Can some one help me out with the below problem:
I have a TabControl in my WindowsForm application, where the tab pages are generated dynamically. The content to be displayed on each tab would be fetched from my database. I need some kind of control (which can display the fetched data) that I can add on each tab page (which would be same for all tabs) such that I can associate some kind of event, say click, on that added control.
Can anyone tell me how to do this programmatically & write the click event for all the controls added?

Please refer the below link! You will get more detail in this regard.
Creating a tab control with a dynamic number of tabs in Visual Studio C#

I'm not sure I completely understand your problem but my initial thoughts are that you could dynamically create a datagrid or something similar for each tab that you are dynmically creating. You could then bind the datasource for the grid and then add the grid as a control to your tabpage.
Something like...
DataGridView gv = new DataGridView();
gv.DataSource = //whatever your source is
this.tabPage1.Controls.Add(gv);
You would then have all the events associated with the grid to work with.

I'm thinking data binding is going to be your best bet for displaying this information. You can create a list of objects and use a DataTemplate to format the data. You can apply the DataTemplate to a quite a few objects. I generally use the ItemsControl and ListBox
http://msdn.microsoft.com/en-us/library/ms750612.aspx
good luck

Related

Programmatically create table with clickable and expandable content in WPF

This is what I desire to create:
As you see I need to create table like control with images and clickable cells. When you click on an arrow on the left it expands its' content and content contains some more additional table like controls with data. Also when user clicks on a Star I need to add this event to Favorites list and etc.
Currently, for each data row I'm thinking of programmatically creating accordion item with Grid in header for images and cells and other Grids for the content.
What is the best and easier way to achieve this task? What controls should I use? I need some suggestions, as I'm new to WPF.
WPF DataGrid can show RowDetails. Customize them with RowDetailsTemplate property and manage their visibility with RowDetailsVisibilityMode property

Add usercontrols dynamically inside a GridView

Here's my problem. I am trying to add usercontrols dynamically to different rows of a GridView.
Let me explain the scenario further. Let's say, I have a page where the user can place orders for different kinds of items. The order form for each item is different in layout and code, and has its own usercontrol. There is an "Add More" button, which lets the user add an extra row to the GridView, while the kind of form that gets appended is selected by the dropdown list (see picture below).
What I am trying to do is - have a separate UserControl for each one of these forms, and then have the UserControl added (or maybe I should say "bound") to the GridView. Every time a new row is added, I plan to re-bind the GridView, including rows from above, to maintain all the rows.
The problem is - the main page cannot know what fields there will be inside each individual UserControl (they can be anything, really, and down the road, newer UCs could be added). So my main question is - how do I bind the data to the GridView, when I do not know what to bind? Is there any way to bind the data from inside each UserControl itself?
I hope my problem and question are clear enough. Thanks for helping.

Syncing two BindingSources

I have a BindingSource in my main form, and I have a DataGridView in a User Control. I'd like to use the main form's BindingSource on the DGV, but I want to use the designer to customize the columns.
In my attempt, I dragged the same data source onto the user control, which created a new binding source. This let me use the designer to customize the columns. Then, in the code behind, I wrote
UserControl.CompaniesBindingSource.DataSource = CompaniesBindingSource
This got the data working, but the Current property isn't syncing up.
Is this possible?
I find that trying to use the Visual Studio Designer for the datagridview and manipulate it programmatically in code is very hard. I have never been able to get both to work how I want it to. What I find programmers do is create the datagridview on the form, but they don't do anything with the designer. Then, the entire datagridview is created and manipulated programmatically which, I know, usually takes extensive programming.

Insert Data Into Listview And Save To SQL Server

am using C#, VS-2005
am new for listview Control in VS-2005. I know how to Insert Records into Listview by typing on Outer Textbox.
But don't know how to directly insert Records on Empty ListView control as it not Focus It's Self.
If any other way or is it possible to insert data directly to ListView Control then Please provide me some code or guide me please.
If you refer to WinForms, see the System.Windows.Forms.ListViewItem Class,
it Represents an item in a ListView control.
ListViewItem class defines the appearance, behavior, and data associated with an item that is displayed in the ListView control. ListViewItem objects can be displayed in the ListView control in one of four different views.
From the example on the same page (see the full example using the ref above):
ListView listView1 = new ListView();
...
ListViewItem item1 = new ListViewItem("item1",0);
...
listView1.Items.AddRange(new ListViewItem[]{item1,item2,item3});
It sounds like you want a grid control rather than a Listview control. In my experience, Listview controls are primarily read-only and grids are editable. Have you considered using a grid?

Creating a tab control with a dynamic number of tabs in Visual Studio C#

How to create a tab control with a dynamic number of tabs in Visual Studio C#?
I've got a database with a table customers. I need to create a form that would show tabs with the first letters of customers' last name (only those first letters, for which there are entries in the table should be present). Each tab should contain a DataGrid control with the corresponding customers. I connect to the database using DataSet.
Where should I insert the code snippet that would generate such tabs? Can I do that with the existing tab control or should I create a custom control?
You can generate dynamic tabs with the existing TabControl. Here is an example of how it can be done in a somewhat sort of pseudo code form...
TabControl tabControl = new TabControl();
tabControl.Dock = DockStyle.Fill;
foreach (Char c in lastNameList)
{
TabPage tabPage = new TabPage();
tabPage.Text = c.ToString();
DataGrid grid = new DataGrid();
grid.Dock = DockStyle.Fill;
grid.DataSource = dataForTheCurrentLoop;
tabPage.Controls.Add(grid);
tabControl.Controls.Add(tabPage);
}
this.Controls.Add(tabControl);
You would add the code to generate the tabs where you determine what letters are required to be shown, probably when you either retrieve the data or in the form's OnLoad() method. You should be able to dynamically add/remove tabs from the built-in tab control. You can check the designer code for some idea how to do it, or the docs.
Note that it isn't necessarily a good idea to add a separate tab for each character. 26 tabs (which will happen when your database gets reasonably large) is a pretty awful number of tabs for someone to look through-- it won't necessarily make things faster at all.
Instead, consider providing a dynamic filtering mechanism, similar to the search box on Vista's start menu. Your user can type a single character (assuming you aren't writing some sort of kiosk or touch-screen-only software) and zoom immediately to the relevant names. This would work ideally with a ListView in List or Details mode.
I don't remember the specifics now. But just look at the code in the XXX.designer.cs file for a form you have that contains a tab control. There you'll see the code generated to add a new tab. Just replicate those lines, you can add a new tab whenever you want.
It sounds like the best route for you would be to create your own custom tab control class. It could inherit from tab control for the bulk of its functionality and properties for the datagrid and whatever else custom you need. Then when you get your customers, you can create a tab for each letter you need and setup the corresponding properties.

Categories

Resources