|
>1.when retrieving an item from an ArrayList you need to cast to the original type.
I know that. Two issues though: (a) where to get information on the type of stored Attribute
(b) how to succesfully unbox object to Attribute<int>, Attribute<string> etc.
>2.when storing different types in a generic, you need to specify a common type
(it could be object or any common ancestor of your types).
I thought that adding an onject to an ArrayList does it automaticaally (I mean conversion to the Object type)
>3.
I am not going into this
SO, I am still in limbo. Thank you for trying to help me
|
|
|
|
|
Hi,
1.
you can retrieve an object from any ArrayList, then check its type, e.g.
object obj=list[0];
Button btn=obj as Button;
if (btn!=null) btn.PerformClick();
2.
ArrayList does not care about the types of objects it is holding.
A generic collection such as List<T> is different:
- it will only accept objects of type T (or derived from T)
- it will automatically return objects of type T, without needing a cast
(making it both safer and faster).
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Luc Pattyn wrote: 1.you can retrieve an object from any ArrayList, then check its type, e.g.
object obj=list[0];
Button btn=obj as Button; // gives either a real Button or null
if (btn!=null) btn.PerformClick();
(a) my objects are Attribute<int>>, Attribute<string> etc. Should I try to cast all variety?
(b) to my great surprise, when I did your line 1 it did return an object with type name
"<assemblyname>.Attribute`1". Here 1 stays for 1 parameter. Moreover, FullName showed this parameter type like String.string in my case
Oh, Mighty Reflection,, the problem is solved
2. I cannot use List<T>, can i? My objects are all different types
thanks
-- modified at 6:35 Thursday 29th November, 2007
|
|
|
|
|
I am creating a windows application using vb .net 2005 (i don't mind c#) and sql server 2005.
i want to print a local (embedded) rdlc report without showing it.
is it possible?
if not, then how do i print the report (displayed in reportiviewer) without showing print dialog.
Thank you.
|
|
|
|
|
People usually frown upon cross posting y'know. Prepare ye'self.
My current favourite word is: PIE!
I have changed my name to my regular internet alias. But don't let the 'Genius' part fool you, you don't know what 'SK' stands for.
-The Undefeated
|
|
|
|
|
|
Thank you Giorgi for the link, I checked out the link, but it uses Reporting Services. and I don't want to use Reporting Services.
My application is actually a Point of Sale which prints the Transaction Bills (embedded report).
Showing the report in the reportviewer and then showing the print dialog irritates the user
alternately, is there any way to print the report to the default printer without showing print dialog.
thank you once again.
|
|
|
|
|
I am trying to datasource a gridview within a repeater. I am having issues passing the data from the repeater to the gridview (either to source it manually or set the Gridview's SQLDataSource attributes wtihin the Repeater_ItemDataBound event.)
The XML will look similar to this (all dummy data):
<root>
<Unit type="District" number="221">
<Employee name="Joe Smith" unitType="Store" unitNum="2213" reviewStatus="Pending" empNum="12345"></Employee>
<Employee name="James Jones" unitType="Store" unitNum="2365" reviewStatus="Pending" empNum="23654"></Employee>
</Unit>
<Unit type="District" number="254">
<Employee name="Rosie Worcester" unitType="Store" unitNum="2369" reviewStatus="Pending" empNum="26358"></Employee>
<Employee name="George Washington" unitType="Area" unitNum="254" reviewStatus="Pending" empNum="95682"></Employee>
</Unit>
</root>
I need an asp:Label within the repeater to load the <Unit> type and number and then pass the employee information to the gridview. Any suggestions on how I might do this? I cannot directly access the Gridview or SQLDataSource within the Repeater_ItemDataBound event.
Thanks in advance!!
K. Garl
|
|
|
|
|
I have a dateTimePicker control on my form and I am working on a payroll entry form. I want the datetimepicker to default to the following sunday for the period ending date, if the user selects a day during the week. does anyone have any suggestions on how i could do this using the ValueChanged event?
Thanks
|
|
|
|
|
DateTime dt=DateTimePicker.Value;
dt=dt.AddDays((7-dt.DayOfWeek)%7);
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
That worked wonders, I can even use the same logic to grab the beginning of the week.
Thanks
|
|
|
|
|
Hi all!
I have a class like this:
class A<br />
{<br />
private string strA;<br />
private B mySubclass = new B();<br />
...<br />
<br />
class B<br />
{<br />
public B()<br />
{<br />
string strB = strA
}<br />
}<br />
}
Is there a way to make strA visible only for class B and not for other classes? If not can you suggest a workaround to do that?
Thank you.
Luca
|
|
|
|
|
You could... pass a reference to your strA to class B through its constructor.
Or, you could probably do something with delegates. I must check up on delegates one day.
My current favourite word is: PIE!
I have changed my name to my regular internet alias. But don't let the 'Genius' part fool you, you don't know what 'SK' stands for.
-The Undefeated
|
|
|
|
|
Thank you! I thought to do that too. It seems to be the simplest way to obtain that I asked
Hope that helps!
Luca
Do rate the reply, if it helps or even if it doesnot, because it helps the members to know, what solved the issue. Thanks!
|
|
|
|
|
If it actually was a subclass, you could just make the string protected.
As B is not a subclass at all, you can't do that. You have to pass a reference to the instance of the class.
Experience is the sum of all the mistakes you have done.
|
|
|
|
|
Thank you for the answer! And how can I do to make B a "real" subclass?
|
|
|
|
|
devzav wrote: And how can I do to make B a "real" subclass?
Inherit from the A class:
class B : A {
...
}
Experience is the sum of all the mistakes you have done.
|
|
|
|
|
I need the "like subclass" I used in the example. So I'll pass a reference to B.
Thank you very much for your answer!
|
|
|
|
|
guys third time posting the question but in vain
i have a table Employee Info in sql 2000
having attributes
EmpID
EmpName
GenID
GenID is a foriegn key of table Gender having attributes GenID and Gender
this.cGender.displaymember = "Gender";
till here every thing is okay
but here the problem arises
the following code is not working why
{this.cGender.valuemember = "GenID";}
i need this code to run bcoz i have to save the value of gender in the Employeeinfo
accoridng to following code
datrow.["EmpID"]= Emp.text;
datrow.["EmpName"]= EmpName.text;
datrow.["GenID"]= cGender.SelectedValue;
sas
|
|
|
|
|
Try writing the code without databinding to get it to work first. It is a good why to identify the exact problem.
Also, without rewriting set a breakpoint on the last line datrow.["GenID"]= cGender.SelectedValue; and examine what is actually in memory.
Need a C# Consultant? I'm available.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
|
|
|
|
|
|
Hi,
I've been searching on the internet for an age and haven't found yet found a solution to what looks like a easy problem. I was hoping you guys might be able to help.
Say I have a few web services like
a. service1.add(int num, int num2)
b. service2.subtract(int num, int num2)
and basically i want a generic runner that can call these services. The tricky thing is that one day I might want to add
c. service3.multiply(int num, int num2)
d. service4.divide(int num, int num2)
and I don't want to compile my generic runner again. All the services take the same number of inputs and return the same type of output. Is there any way of doing this.
From what I have read, it seems that the simplist way would be to use MSSOAP, I've managed to connect to an arbitary service, but don't know how you'd go about invoking the methods.
Thanks
|
|
|
|
|
Wii.lliam wrote: generic runner
My first suggestion is "don't make up terminology". In text based communications it is difficult for people to understand what you say.
Wii.lliam wrote: I don't want to compile my generic runner again. project
Using configuration mechanisms to avoid hard coding information into software is not a new concept. There are many ways to do it. One widely used approach today is to use XML files.
Wii.lliam wrote: I've managed to connect to an arbitary service, but don't know how you'd go about invoking the methods.
Again there are many ways to go about that as well and one is WSDL[^]
|
|
|
|
|
Can you somehow use reflection on web services? Perhaps all of your services (like service1, service2, etc. from your example) could export a property that returns a MethodInfo[] will all its methods, and you could call them (add, subtract, multiply, and divide) from that array? Does your main service know that all sub-services implement only those four methods, or could they implement some arbitrary unknown method that you want to export, like say sqrt? If the methods are known, then you could, upon finding a service, make a call to all the possible methods, and the ones that error MAY not be exported by that service, but the ones that work will for sure be available. So, for example, you set up service4, then your mainService would find service4, then make a call to service4.add(1, 1), which would error. Then you make a call to service4.divide(1, 1), which would possibly not error, in which case you would know that method is exported. I'm not familiar with web services, so I'm just throwing out ideas...
Jeff
|
|
|
|
|
Use an object as your parameter: (I typed this quickly but obviously use Properties)
public class Foo{
public string Method;
public int Num1;
public int Num2;
}
[WebMethod]
public void FooBar(Foo foo){}
Need a C# Consultant? I'm available.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
|
|
|
|