Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

am I being dumb here? Prob with TabControl

Status
Not open for further replies.

CADTenchy

Technical User
Dec 12, 2007
237
GB
I have a tabcontrol with 3 tabs.
Onto it have have placed a treeview and 2 listviews, all aligned alClient.

Then I am using this code to show the correct component per tab:
Code:
procedure TMainForm.TabControl1Change(Sender: TObject);
begin
if TabControl1.TabIndex = 0 then 
  begin
    TreeView1.Visible := true;
    ListView1.Visible := false;
    ListView2.Visible := false;
  end;
if TabControl1.TabIndex = 1 then 
  begin
    TreeView1.Visible := false;
    ListView1.Visible := true;
    ListView2.Visible := false;
  end;
if TabControl1.TabIndex = 2 then 
  begin
    TreeView1.Visible := false;
    ListView1.Visible := false;
    ListView2.Visible := true;
  end;  
end;

In the editor I can see the column headings of both listviews.
Both are set to visible=false in the editor, the treeview set to visible=true.
But when I run the prog and cycle the tabs, I cannot ever see ListView1.
I see TreeView1 on tab 1 OK, Listview2 column headings on tab3 OK, but nothing on tab 2.
I've checked through every single property and can see nothing that isn't the same.
Previously in this project I had 3 Treeviews, and I got it working no problem with same code concept as above.
Now I've swapped out two of them for ListViews I have this problem.

Any idea what is wrong?


Steve (Delphi 2007 & XP)
 
why use tabs to do this, use pagecontrol, then you dont need any of this code.

Aaron
 
Steve,

In a previous thread I recommended that you use TPageControl and Aaron has also suggested this. Is there a technical reason why you don't? I find TPageControl easier to use than TTabControl. It is available in D7 although it wasn't available in early versions of Delphi.

Assuming that TPageControl is available in your version of Delphi, I doubt if there is any situation where TTabControl is preferable to TPageControl.

Having said that, I tested the above code out and it worked perfectly for me.

Andrew
Hampshire, UK
 
I would subscribe to the suggestion of using a TPageControl since you can manipulate the individual TabSheets with the boolean property PageVisible

The TPageControl is available at least since Delphi IV.

Steven
 

I've now tried the pagecontrol, which is so much better.
(I've had so many small things to fix or get working I kinda sidelined the tabbed part till yesterday until I needed to actual write the code for populating the string containers that appear on the tabs.)

However, I was still getting the same problem with one of the listviews not showing.

I thought there must be some problem with it, so I deleted it, and copied and pasted the 'good' one, and named it as the deleted one was, ignoring the fact they both got same columns now.

Still no good.

Next I swapped the listviews onto each others tabs.

Same listview not shown on new tab! (Everything fine in designer BTW in all cases)

Next I tried changing the name of the 'dodgy' one.

Then it showed OK !!

I then named it back to original name, still OK.

HUH?!

Some tempory glitch I guess. Thanks for the replies, and I shall NEVER bother with a TabControl again!



Steve (Delphi 2007 & XP)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top