Adding a control to tabs generated dynamically in tabcontrol in C # .net

I am new to C # .NET.

Can someone help me solve the problem below:

I have a TabControl in my WindowsForm application where tab pages are generated dynamically. The content that will be displayed on each tab will be retrieved from my database. I need some kind of control (which can display the extracted data) that I can add to each tab (which would be the same for all tabs) so that I can associate some kind of event, such as a click, with this added control.

Can someone tell me how to do this programmatically and write a click event for all added controls?

+3
source share
3 answers

Please refer to the link below! In this regard, you will receive more detailed information.

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

+3
source

I'm not sure I fully understand your problem, but my initial thoughts are that you can dynamically create a datagrid or something similar for each tab you dynamically create. Then you can snap the data source to the grid, and then add the grid as a control to your tab.

Sort of...

DataGridView gv = new DataGridView();
gv.DataSource = //whatever your source is            
this.tabPage1.Controls.Add(gv);

After that, you will have all the events related to the grid.

+1

I think data binding would be your best bet to display this information. You can create a list of objects and use the DataTemplate to format the data. You can apply a DataTemplate to multiple objects. I usually use ItemsControl and ListBox

http://msdn.microsoft.com/en-us/library/ms750612.aspx

luck

0
source

Source: https://habr.com/ru/post/1710480/


All Articles