|
-
Feb 9th, 2004, 05:31 PM
#1
Thread Starter
Lively Member
syncing tabpages to listview lines
Some of you may remember that I wrote a program that read in a bunch of lines from a text file, parsed the data on each line, and displayed the results on tab pages, one tab page per line of data. It went something like this:
File:
Code:
Line1 yaddayaddayadda
Line2 blahblahblah
Line3 spamspamspamspam
Then the program would make 3 tab pages and list the data like this:
Tabpage1:
Code:
HEADER Line1
ELEMENT1 yadda
ELEMENT2 yadda
ELEMENT3 yadda
Tabpage2:
Code:
HEADER Line2
ELEMENT1 blah
ELEMENT2 blah
ELEMENT3 blah
Tabpage3:
Code:
HEADER Line3
ELEMENT1 spam
ELEMENT2 spam
ELEMENT3 spam
ELEMENT4 spam
What I would like to do is take each line of data and put it in a listview, then as a tabpage is selected, the corresponding line in the listview would get highlighted. So if I am looking at Tabpage 3, then Line3 would be highlighted.
My problem is that I don't quite know where to begin. Building the listview would not be a big deal. I have to read each line in to parse it anyway, it would only take a line or two of code to throw it in a listview.
My main question is where would I put the code that detects which tab page is selected and highlights the line in the listview? Would this be in the tabcontrol, or what?
-
Feb 12th, 2004, 11:02 AM
#2
Thread Starter
Lively Member
BUMP!
Please someone? I'm still at a loss here.
-
Feb 13th, 2004, 11:00 AM
#3
Thread Starter
Lively Member
Alright.
So I figured most of this out. My program adds tabpages dynamically because I never know how many lines an input file will have. What I did with that is I added an index counter (tpindex) to assign a tabindex to each tabpage.
VB Code:
TmpTabPage.TabIndex = tpindex
Also, I throw the string read in from the input file (InputStr) into a listbox on form 2 which I declared in a module. As above I assinged it an index (lbindex). In retrospect, I probably should have used tpindex instead.
VB Code:
Frm2.ListBox1.Items.Add(InputStr)
Frm2.ListBox1.SelectedIndex = lbindex
Then I added this to detect when the selected tabpage changes. (lbflag is a flag that prevents this code from running until the input file has been loaded into the application, otherwise it has problems)
VB Code:
Private Sub TabControl1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged
If lbflag = 1 Then
Frm2.ListBox1.SelectedIndex = Me.TabControl1.SelectedIndex
End If
End Sub
I had planned on swapping the line
VB Code:
Frm2.ListBox1.SelectedIndex = Me.TabControl1.SelectedIndex
for use with the listbox. (I want to be able to click on the listbox and the corresponding tabpage would be selected) but I couldn't figure out how to reference form 1. Any Ideas?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|