创建在Visual Studio C#标签的动态数字选项卡控件 [英] Creating a tab control with a dynamic number of tabs in Visual Studio C#

查看:339
本文介绍了创建在Visual Studio C#标签的动态数字选项卡控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Visual Studio C#标签的动态数字创建一个标签控制?

How to create a tab control with a dynamic number of tabs in Visual Studio C#?

我有一个表的数据库客户。我需要创建一个表单,将显示与客户的姓氏的第一个字母(仅限第一字母,其中有在表中应该存在的条目)标签。每个标签都应该包含与相应的客户DataGrid控件。我连接到使用DataSet中的数据库。

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?

推荐答案

您可以生成动态标签现有TabControl的。下面是它如何能够以某种形式的伪代码形式来完成...

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);

这篇关于创建在Visual Studio C#标签的动态数字选项卡控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆