Hi,
i wanted to make a generec fntions which will compare a given object type against a lit of objects.
my list of object are a set of forms, but sor simplicity lets assume it to be a lit of int, string, float, decimal, etc
my function should get a parameter which is an int,string,etc
inside we have to check if any object within the list is the same data type as the parameter.
Is there any predefined Data Type or some similar method?
thanks
7 1371
Hi,
i wanted to make a generec fntions which will compare a given object type against a lit of objects.
my list of object are a set of forms, but sor simplicity lets assume it to be a lit of int, string, float, decimal, etc
my function should get a parameter which is an int,string,etc
inside we have to check if any object within the list is the same data type as the parameter.
Is there any predefined Data Type or some similar method?
thanks
C# has the is operator.
Also all objects are inherit from System.Object so they all have the GetType method.
Ok, cool, thank for that !
howevere if this is my method - private Form checkForms(<FormDataType> frm)
-
{
-
foreach(Form f in this.MdiChildren)
-
{
-
if(f is frm)
-
return f;
-
}
-
return null;
-
}
So that is what my code should look like... I cant think of the parameter datatype (ie <FormDataType>) if i have 3 forms namely frm1,frm2,frm3
I wuold like to go throug each MDIChild, and if it matches frm1/2/3 (which ever is sent as a param) it should return the mdiChild so that i can focus it.
At the moment, I instantiate the form object, and compare the names of the mdiChildren (for some reson it dosent work, but will work on it)
Is there any other way especially with the datatype that i should be sending?
Ok, cool, thank for that !
howevere if this is my method - private Form checkForms(<FormDataType> frm)
-
{
-
foreach(Form f in this.MdiChildren)
-
{
-
if(f is frm)
-
return f;
-
}
-
return null;
-
}
So that is what my code should look like... I cant think of the parameter datatype (ie <FormDataType>) if i have 3 forms namely frm1,frm2,frm3
I wuold like to go throug each MDIChild, and if it matches frm1/2/3 (which ever is sent as a param) it should return the mdiChild so that i can focus it.
At the moment, I instantiate the form object, and compare the names of the mdiChildren (for some reson it dosent work, but will work on it)
Is there any other way especially with the datatype that i should be sending?
It doesn't look like you are comparing types then. The "is" operator is used to check whether the run-time type of an object is compatible with a given type.
If you want to check for equality you should use the Equal method instead.
thanks anyways,
i have taken the longer approach. I hope i will get the more generic one worked out some other day.
Atthe end of this day, made it work good
You should use "Object" as the type for the argument you pass in.
Although I don't know what this accomplishes as you already have your frm1 frm2 frm3 objects available to you.
You should use "Object" as the type for the argument you pass in.
Although I don't know what this accomplishes as you already have your frm1 frm2 frm3 objects available to you.
its something like amdi parent with 3 buttons to open the 3 different forms.
but there can only be one instance of each form, so if any of the button is clicked, the form type is sent to this method which searches all the forms contained in that mdiparent if it is of that form type.
if i pass an object, i would have to instantiate it and then discard it later.
Could you not just disable the button when the child window is created and then when it is closed re-enable the button?
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Chris Fink |
last post by:
This should be relatively simple but I am unable to find an asp:button tag in
a datalist footer. I have tried it numerous ways including the FindControl
method from the many events that the...
|
by: one man army |
last post by:
Hi All-
I am new to PHP. I found FAQTS and the php manual. I am trying this
sequence, but getting 'no zip string found:'... PHP Version 4.4.0
$doc = new DomDocument;
$res =...
|
by: SunnyDrake |
last post by:
HI!
I wrting some program part of it is XML config parser which contains
some commands(for flexibility of engenie).
how do i more simple(if it possible not via System.Reflection or...
|
by: Neehar |
last post by:
Hello
For one of the interviews I took recently, I was given an offline
programming quiz.
In 30 minutes I had to write code in C++ to counts the number of times
each unique word appears in a...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
| |