473,785 Members | 2,363 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Overloaded function with ListControl parameter

Vit
Hi.
I'd like to pass as a parameter of class method reference
to ListControl (ListBox or ComboBox).
Here is my call:
public DoSomething(Lis tControl lc){}
It's ok with that, but lc does not have methods like
lc.BeginUpdate;
lc.EndUpdate
but ListBox and ComboBox does have such a methods.
I don't like two methods like
public DoSomething(Lis tBox lc){};
public DoSomething(Com boBox lc){};
Is there a way to do that in one method and have abilities
to use .BeginUpdate and .EndUpdate ?


Nov 15 '05 #1
1 1899
Guy
Construct the method as you have, accepting a ListControl
as the parameter. Like so....

public DoSomething(Lis tControl lc)
{
//now check the param for its type
if(lc is ListBox)
{
//create a listbox from the param and use it
ListBox lb = (ListBox)lc;
//TODO do stuff with listbox..
}
if(lc is ComboBox)
{
//create a combo from the param and use it...
ComboBox cb = (ComboBox)lc;
//TODO do stuff with combo...
}

What you are doing is checking the parameter
for the object type you are looking for by using
the 'is' keyword and then casting your param
over to that type in a new variable specifically
of that type.

Hope this helps

Guy
-----Original Message-----
Hi.
I'd like to pass as a parameter of class method referenceto ListControl (ListBox or ComboBox).
Here is my call:
public DoSomething(Lis tControl lc){}
It's ok with that, but lc does not have methods like
lc.BeginUpdate ;
lc.EndUpdate
but ListBox and ComboBox does have such a methods.
I don't like two methods like
public DoSomething(Lis tBox lc){};
public DoSomething(Com boBox lc){};
Is there a way to do that in one method and have abilitiesto use .BeginUpdate and .EndUpdate ?


.

Nov 15 '05 #2

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

Similar topics

8
17879
by: Nitin Bhardwaj | last post by:
Thanx in advance for the response... I wanna enquire ( as it is asked many a times in Interviews that i face as an Engg PostGraduate ) about the overloading capability of the C++ Language. Why can't the = (assignment) operator be overloaded as a friend function ? I work in VS 6.0 ( Win2000 ) as when i referred the MSDN documen'n it said the following :
9
462
by: August1 | last post by:
Below are the declaration for an overloaded assignment operator in an interface file in addition to the implementation file definition of the function. What would be an appropriate if condition to ensure that a client of the program cannot assign an object of the class to itself. The if() condition would be placed within the function definition to compare the operand in the function parameter is not the same as the temporary object being...
3
1725
by: Elad Volpin | last post by:
Can someone please explain this: I created a new webform with a PlaceHolder and a Button. My Page_Load contains the following code: private void Page_Load(object sender, System.EventArgs e) { ListControl l = null; ListItem item = new ListItem("a", "b");
4
1839
by: Vish | last post by:
Hi all, I am having a build error in one of the overloaded functions in my class. The function takes either a string as a parameter or a type referenced in another dll as a parameter. My class references the dll where the type of the parameter is defined. I am able to create to create my class in a form without any build errors and without any references to the DLL where the other parameter type is defined. The form only uses the...
10
2628
by: Grizlyk | last post by:
1. Can abybody explain me why C++ function can not be overloaded by its return type? Return type can has priority higher than casting rules. For example: char input(); //can be compiled to name "input$char$void" int input(); //can be compiled to name "input$int$void" .... int i= 3+'0'+input(); //can be compiled to: int(3)+int('0')+input$int$void()
9
8179
by: rohits123 | last post by:
I have an overload delete operator as below ////////////////////////////////// void operator delete(void* mem,int head_type) { mmHead local_Head = CPRMemory::GetMemoryHead(head_type); mmFree(&local_Head,(char *)mem); CPRMemory::SetMemoryHeadAs(local_Head,head_type); } ///////////////////// void* operator new(size_t sz, int head_Type) {
1
3016
by: mersinli | last post by:
Hi, I have got seven error and I dont find why compiler find error.. //commission class definition #ifndef COMMISSION_H #define COMMISSION_H #include <string> using std::string;
2
1069
by: gkinu | last post by:
I want to write an overloaded function. Each overload will take as parameter one of different command objects like MySqlCommand, SqlCommand, OledbCommand etc and different DataAdapters. The function has many lines of code and the command object passed as a parameter will be referenced many times in the code. However, most lines of code do not reference the passed parameter value. My question is, do i have to repeat the whole function (duplicate...
3
6406
by: mathieu | last post by:
Could someone please tell me what is wrong with the following -ugly- piece of c++ code. Why when I explicititely set the template parameter my gcc compiler start getting confused: bla.cxx: In function 'int main()': bla.cxx:25: error: call of overloaded 'foo(short unsigned int*&)' is ambiguous bla.cxx:2: note: candidates are: void foo(OutputType*) bla.cxx:10: note: void foo(PixelType*)
0
9647
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
10161
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7506
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
6743
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
5390
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5523
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4058
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
3662
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2890
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.