Results 1 to 6 of 6

Thread: [RESOLVED] Reminder - Listbox with item can't select generated tab

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2014
    Posts
    7

    Resolved [RESOLVED] Reminder - Listbox with item can't select generated tab

    Hello, i have problem.
    I make program, that is something like reminder
    Here is code:

    Private Sub save()
    Dim t As New TabPage
    Dim newt As New Template

    Form1.ListBox1.Items.Add(DateTimePicker2.Text & " | " & TextBox1.Text)
    newt.Show()
    newt.TopLevel = False
    newt.Dock = DockStyle.Fill
    t.Controls.Add(newt)
    t.Name = TextBox1.Text
    Form1.TabControl1.TabPages.Add(t)

    ' And here, if i select added item from list box then tabcontrol select added tab(t)
    ' I want this for each item. 1 item = 1 generated template.

    ' ˇˇˇ Here is my idea, but it doesn't work ˇˇˇ

    If Form1.ListBox1.SelectedItem = DateTimePicker2.Text & " | " & TextBox1.Text Then
    Form1.TabControl1.SelectedTab = t
    End If
    End Sub

  2. #2
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: Reminder - Listbox with item can't select generated tab

    Not sure I really understand the question, so FWIW, one way might be to use the datetime+textbox for the tabpage Name, then loop & compare to that...

    Code:
    Dim dtp As String = DateTimePicker2.Text & " | " & TextBox1.Text
    Form1.ListBox1.Items.Add(dtp)
    
    newt.Show()
    newt.TopLevel = False
    newt.Dock = DockStyle.Fill
    
    t.Name = dtp
    t.Controls.Add(newt)
    Form1.TabControl1.TabPages.Add(t)
    Code:
    Dim dtp As String = DateTimePicker2.Text & " | " & TextBox1.Text
    If Form1.ListBox1.SelectedItem.ToString = dtp Then
        For Each t As TabPage In Form1.TabControl1.TabPages
            If t.Name = dtp Then
                Form1.TabControl1.SelectedTab = t
                Exit For
            End If
        Next
    End If

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2014
    Posts
    7

    Re: Reminder - Listbox with item can't select generated tab

    Name:  USoc3st.jpg
Views: 736
Size:  10.2 KB
    Ok, now if i choose one of these generated item in listbox, so I will not see any card..
    I want this, if i choose one of these generated item then tab with same name show.

    I tried this, but its crap:

    Code:
    ListBox1.SelectedItem = TabControl1.SelectedTab.Text
    Thank you for answers.

  4. #4
    Member vbProsecutor's Avatar
    Join Date
    Jun 2014
    Location
    Canada (I'm sorry)
    Posts
    60

    Re: Reminder - Listbox with item can't select generated tab

    For that, take Edgemeal second code block, change it a bit and put it in the ListBox's click event.

    Code:
    Dim selected As String = Form1.ListBox1.SelectedItem.ToString()
    For Each t As TabPage In Form1.TabControl1.TabPages
        If t.Name = selected Then
            Form1.TabControl1.SelectedTab = t
            Exit For
        End If
    Next

  5. #5

    Thread Starter
    New Member
    Join Date
    Jan 2014
    Posts
    7

    Re: Reminder - Listbox with item can't select generated tab

    It's work, i just had to delete "ToString" from SelectedItem

    Code:
    Dim selected As String = ListBox1.SelectedItem
            For Each t As TabPage In TabControl1.TabPages
                If t.Text = selected Then
                    TabControl1.SelectedTab = t
                    Exit For
                End If
            Next
    Thank you

  6. #6
    Member vbProsecutor's Avatar
    Join Date
    Jun 2014
    Location
    Canada (I'm sorry)
    Posts
    60

    Re: Reminder - Listbox with item can't select generated tab

    Then please mark this thread as solved in the thread tools. You are welcome.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width