473,805 Members | 1,887 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

need help improving this code

..NET 2.0

I've created a window consisting of a treeview control and a tabcontrol.

When a leave in the treeview is clicked then the code should check if the
specific tabpage already exists in the tabcontrol and give it focus if it
exists. Or else if it doesn't exists then add the tagpage to the tabcontrol.

Below is the code which checks if a tabpage already exists and if it does
then give it focus... If you have a suggestion on improving the code below
or other suggestions (maybe .NET has some built in features which can handle
this??) then please share them with me

private bool GetTab(string tab)
{
bool value = false;
int index = 0;
foreach (TabPage c in tabMain.Control s )
{
if (c.Text == tab)
{
value = true;
tabMain.Selecte dIndex = index;
}
index++;
}
return value;
}

any suggetions?
Oct 14 '07 #1
3 1546
Jeff,

Yes, instead of searching all the tab pages at the same time, why not
set the Tag property of the TreeViewNode to the tab page itself when it is
created. Then, when you check the leaf, if the Tag property has the
reference, just set the focus to that, otherwise, if it doesn't, create and
add the tab page and set the Tag property. This way, you don't have to
search the tab page list every time.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Jeff" <it************ @hotmail.com.NO SPAMwrote in message
news:Ok******** ******@TK2MSFTN GP06.phx.gbl...
.NET 2.0

I've created a window consisting of a treeview control and a tabcontrol.

When a leave in the treeview is clicked then the code should check if the
specific tabpage already exists in the tabcontrol and give it focus if it
exists. Or else if it doesn't exists then add the tagpage to the
tabcontrol.

Below is the code which checks if a tabpage already exists and if it does
then give it focus... If you have a suggestion on improving the code below
or other suggestions (maybe .NET has some built in features which can
handle this??) then please share them with me

private bool GetTab(string tab)
{
bool value = false;
int index = 0;
foreach (TabPage c in tabMain.Control s )
{
if (c.Text == tab)
{
value = true;
tabMain.Selecte dIndex = index;
}
index++;
}
return value;
}

any suggetions?
Oct 14 '07 #2
thanks, but when I have a reference to the tabpage in the treeviewitem's tag
property. How do I give this tabpage focus? All I got is the reference to
the tabpage, and I AFAIK I cannot use that value on tabcontrol.sele ctedindex
?

any suggestions?

Jeff
Oct 14 '07 #3
Jeff,

You don't have to store the tab page. You can store the index of the
tab page in the Tag property (if it is null, then you know there is no tab
page) and then set the selected index to that.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Jeff" <it************ @hotmail.com.NO SPAMwrote in message
news:uk******** ********@TK2MSF TNGP06.phx.gbl. ..
thanks, but when I have a reference to the tabpage in the treeviewitem's
tag property. How do I give this tabpage focus? All I got is the reference
to the tabpage, and I AFAIK I cannot use that value on
tabcontrol.sele ctedindex ?

any suggestions?

Jeff
Oct 14 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
6407
by: Megha Vishwanath | last post by:
Hi, We have an application where my clients may be at different timezones. I need to validate time across the timezones with javascript. The date object in JavaScript does not allow me to get the timezone. Any implementation suggestions? Thanks
4
3354
by: Guy | last post by:
I got a big Access file (1 400 tables) to convert to SQL and I would like to be provided with some automated tools, except upsizing wizard and DTS, to convert it on my own. I got a lot of forms and query to convert too. Can someday provide me with at least one tool name ? Thanks,
23
2607
by: Adam | last post by:
I am coding a microkernel based off of Tanebaum's theroy. For Isis to be extensible, fast, and secure, it has been decided it will be a microkernel. Not in the old Mach sense of the word, but in the size of the entire project. It is a microkernel, that will limit interprocess communication. But as Tanenbaum says, you learn nothing by reading theroy alone. The code should be self-explaintory. Another reason I choose the microkernel method...
1
1148
by: Robin | last post by:
For an asp.net project that is deployed to a load balanced web servers, are there any performance changes that can be made in .Net runtime or IIS 6? Also are there any additional tips for reviewing the asp.net (VB) code for improving performance?
2
1167
by: Irfan Akram | last post by:
Hi Guys, I am in search of some innovative ideas in improving the interface of Online Marking System. At the moment it has some good functionality, but lacks a professional interface. Is there a way of improving the whole interface of the system to make it look consistent as well as professional. Any useful links will be appreciated! Also, how can we copy incorporate the same layout of an existing web-site in
1
2004
by: Larry Neylon | last post by:
Hi, I'm working on a VBScript application on IIS6 and I'm looking for some advice about the best way of replacing or improving session variable usage. The application is in a secure extranet environment. Currently the application has a search customers page with 10 search fields which list the results below the search fields. The requirement for this screen was that the user could return to this result page at any point from any page...
18
2345
by: bsruth | last post by:
I tried for an hour to find some reference to concrete information on why this particular inheritance implementation is a bad idea, but couldn't. So I'm sorry if this has been answered before. Here's the scenario: We have a base class with all virtual functions. We'll call this the Animal class. We then make two classes Fish and Bird that both inherit from Animal. In the program, we have a single array of Animal pointers that will...
1
1281
by: samadams_2006 | last post by:
Hello, I have Visual Studio 2005 and am developing my first web site. I see TreeViews, ReportViewers, etc. but I'm not sure which approach that I should choose. Let me tell you what I'm going to do and maybe you can offer suggestions: 1) I'm going to have a bunch of articles that I'm going to be posting to this website. 2) I need some sort of "tab" or "tree" structure to the left that
51
2615
by: cool_ratikagupta | last post by:
hello friends i ha just started learning c can u all give me the tips to make myself strong in c lanuage . as i want to be the best in watever i do . so just a request from all of u here plz help me out in improving my c .plz guide me as a techer . to do my best in c lanuage . i m clear with the concepts i just want to improve in c . as programming is best when u use less memory space n less ilterations.
0
9716
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10609
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9185
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7646
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6876
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5677
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4323
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3845
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.