3

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?

3 Answers 3

3

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#

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

0

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

1 Comment

You missed the "winforms" part of his quesiton

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.