C# 如何以编程方式将 Tab 添加到 TabControl 并将 ListView 控件停靠在其中?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/499848/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 05:47:09  来源:igfitidea点击:

How to programmatically add a Tab to TabControl with a ListView control docked inside it?

c#vb.netlistviewtabstabcontrol

提问by user57175

I'm using Visual Basic 9 (VS2008)

我正在使用 Visual Basic 9 (VS2008)

I want to create new Tabs as and when the user clicks an Add Tab button.

我想在用户单击“添加选项卡”按钮时创建新选项卡。

The Tab must have a ListView control docked inside it.

Tab 必须有一个停靠在其中的 ListView 控件。

How to programmatically add a Tab to TabControl with a ListView control docked inside it?

如何以编程方式将 Tab 添加到 TabControl 并将 ListView 控件停靠在其中?

采纳答案by Inisheer

It will go something like this...

它会像这样......

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    // Create the listView
    Dim lstView As New ListView()
    lstView.Dock = DockStyle.Fill
    lstView.Items.Add("item 1") //item added for test
    lstView.Items.Add("item 2") //item added for test

    // Create the new tab page
    Dim tab As New TabPage("next tab")
    tab.Controls.Add(lstView) // Add the listview to the tab page

    // Add the tabpage to the existing TabCrontrol
    Me.TabControl1.TabPages.Add(tab)

End Sub