vb.net - How do I open up a certain TabPage based on data in a ListView?
问题描述
I have created 2 forms: Form1
and Form2
. Form1
contains my TabControl
which has 5 TabPages
. There are 5 TabPages
: 'Special Incident Entry', 'Accident Incident Entry', 'General Incident Entry', 'Injury Incident Entry', and 'Workplace Violent Incident Entry'.
My Form2
contains a ListView
. I created a column header named "Entry Type". Now there are 5 entry types: 'Special Incident Entry', 'Accident Incident Entry', 'General Incident Entry', 'Injury Incident Entry', and 'Workplace Violent Incident Entry'. What I'm trying to accomplish is this:
When the user double clicks on any item in the ListView
, based on what is stated under the column "Entry Type" for that item, the corresponding TabPage
opens containing form controls.
I've tried Form1.TabControl1.SelectedIndex = 1
and that opens up the TabPage
with the index 1. How do I get the 'Entry Type' input from the ListView
on Form2
then open the respective TabPage
on Form1
? Ive added test data into my ListView
to try and figure it out.
解决方案
使用双击事件并获取相应子项中的值。然后在 Select Case 中使用该值来选择正确的选项卡。
Private Sub ListView1_DoubleClick(sender As Object, e As EventArgs) Handles ListView1.DoubleClick
'Use whatever SubItem index is the appropriate column
Dim strTabName As String = ListView1.SelectedItems(0).SubItems(0).Text
Select Case strTabName
Case "Special Incident Entry"
Form1.TabControl1.SelectedIndex = 0
Case "Accident Incident Entry"
Form1.TabControl1.SelectedIndex = 1
Case "General Incident Entry"
Form1.TabControl1.SelectedIndex = 2
Case "Injury Incident Entry"
Form1.TabControl1.SelectedIndex = 3
Case "Workplace Violent Incident Entry"
Form1.TabControl1.SelectedIndex = 4
Case Else
MessageBox.Show("Please try double clicking again.")
End Select
End Sub
推荐阅读
- c - Xlib:如何检查特定窗口是否最小化?
- clickonce - ClickOnce 在应用程序升级后创建新的快捷方式(后缀 -1、-2)
- python-3.x - Python AWS S3 下载 S3 文件以 ZIP 格式保存
- material-ui - Material-ui V5中如何替换隐藏组件
- amazon-web-services - creating external table with partition in ATHENA results in empty table
- python - 规范化 json 列并与数据框的其余部分连接
- vue.js - 能够在特定条件下启用元素 UI 中的行单击 VueJS
- c# - 如何在 BFF 中使用 Azure AD 的 AuthorizeforScopes 在根上提供 SPA
- python - Python maketrans function
- asp.net-mvc - Jquery ajaxsetup:仅捕获 401 错误,否则让自定义错误处理程序完成工作