views:

1828

answers:

3

Hi everyone, i am new to C# .net. Can some one help me out with the below prblm: I have a tabcontrol in my windows form application, where the tab pages are generated dynamically. the content to be displayed on each tab wud 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 wud 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.

A: 

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.

MDStephens
A: 

Please refer the below link! You will get more detail in this regard.

http://stackoverflow.com/questions/1084098/creating-a-tab-control-with-a-dynamic-number-of-tabs-in-visual-studio-c

Srikanth V M
A: 

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

Travis