|
ArrayList has a ToArray() method, and your array can be added one by one to a new ArrayList when you create it, or using the AddRange method
Current blacklist
svmilky - Extremely rude | FeRtoll - Rude personal emails | ironstrike1 - Rude & Obnoxious behaviour
|
|
|
|
|
ArrayList list = new ArrayList( myArray );
int[] ia = list.ToArray( typeof(int) ) as int[];
|
|
|
|
|
while reconverting back to array of bytes i got an InvalidCastException error message:
"At least one element in the source array could not be cast down to the destination array type."
byte[] myArr = (byte[])myList.ToArray(typeof(byte));
why can't it cast every object to the specified byte type?
Donkaiser
|
|
|
|
|
There must be something in the ArrayList which is not a byte (or not able to be converted to a byte).
Josh
|
|
|
|
|
You are linkely adding ints to the Arraylist, make sure you cast them to byte before adding.
|
|
|
|
|
In answer to both questions, when you need to work with arrays dynamically, use collections (or in .NET2 List<> ).
The reasons
1) Collections can be cleared with a .Clear() method
2) Collections allow dynamically adding (.Add(value) ) and inserting (.Insert(index,value) ) new items.
Current blacklist
svmilky - Extremely rude | FeRtoll - Rude personal emails | ironstrike1 - Rude & Obnoxious behaviour
|
|
|
|
|
Thank ya'll so much!
Donkaiser
|
|
|
|
|
Thanks you all,
It was kinda a pain to convert to list and back to array. so what i did was to write an algorithm for it.
int[] myarr;
int index;
in val;
for (int i= myarr.length-1; i > index ; i--)
{
myarr[ i ] = myarr[i-1]; // shift everything;
}
myarr[index] = val;
Well there's always a way to get around thing.
Donkaiser
|
|
|
|
|
I declared a property of type string. In one of my codes i am using the value of property and storing into a local string variable. But i am unable to use ToString(), IndexOf, ToUpper() etc methods of local string variable. Any reason, Help very urgent
thanks
san
|
|
|
|
|
kumar.bs wrote: But i am unable to use ToString(), IndexOf, ToUpper() etc methods of local string variable.
What do you mean by that? You should post the relevant code so that we can see the situation in context.
Josh
|
|
|
|
|
public string DisplayFormat { get, set };
string strDisplayFormat = DisplayFormat;
on strDisplayFormat variable , i could not able to use ToString(), IndexOf() methods
san
|
|
|
|
|
What do you mean by saying that you can't use those methods? What actually prevents you from doing so, a compiler error? If so, what is the error message?
|
|
|
|
|
Josh Smith wrote: a compiler error
I put my money on Intellisense not showing it
|
|
|
|
|
|
I wrote this function to handle an exception for a FileSystemWatcher, so it gets called like this:
watchSamples01.Created += new FileSystemEventHandler(MoveFileFromSharedLog1);
where watchSamples01 is my FileSystemWatcher, and MoveFileFromSharedLog1 is my event handling function.
The method looks like this:
private static void MoveFileFromSharedLog1(object sender, System.IO.FileSystemEventArgs e)
My question is how do I send an additional parameter to my method? I would like to send an integer value to the MoveFileFromSharedLog1 method. If I try to add int x after System.IO.FileSystemEventArgs e I get this error:
Error 1 No overload for 'MoveFileFromSharedLog1' matches delegate 'System.IO.FileSystemEventHandler'
How should I do this?
|
|
|
|
|
You can't alter an event handling method's signature and expect the event's associated delegate to accept your method as a valid target. The method's signature must conform to the delegate's signature. What you should do is store the integer in the class which contains the method, as a field exposed as a property.
Josh
|
|
|
|
|
You can't.
Simply spoken, when registering to the Created event, you tell the FileSystemWatcher to call your MoveFileFromSharedLog1 method whenever this event occurs. The registered method must have a specific signature (defined by delegate FileSystemEventHandler') cause otherwise it couldn't be called. The FileSystemWatcher would have no knowledge what to do with an additional int parameter and which value it should have.
Anyway, what should this int parameter be for?
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
www.troschuetz.de
|
|
|
|
|
I need to setup a path to write a file to, and the path changes depending which folder the file was created on. I figured it would be quick and easy to send in a int parameter and just say writePath =("c:\path\blah" + x); so if x came in as 1 it would write to the c:\path\blah1\, 2 would write to c:\path\blah2\ and so on.
As it is now I have 2 MoveFileFromsharedLog methods and the only difference is the writePath variable. Seems very wasteful, but not sure how else I could do it.
|
|
|
|
|
aquacadet wrote: the path changes depending which folder the file was created on
Use the FileSystemEventArgs.FullPath property to determine in which folder a file was created.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
www.troschuetz.de
|
|
|
|
|
hi all,
i have a form with many labels, textboxes or button on it.
i copied each and every labels', texboxes' and buttons' texts and place them in a txt file. then translated everything between (")-(") into english.(mainform is in my language.)
and through menustrip one can select his/her desired language. (english or turkish)
everythin works fine and i can change every label, textbox or button text.
but for messagebox'es i havent got a solution yet
for example:
in turkce.txt: this.label1.Text="Ingilizce"; translated as:
in english.txt: this.label1.Text="English";
but for error messages for now i cant do nothin
there's no this.messagebox.... ?
do i have to check the form's language first and show error messages according to the language ? or is there an easy way to reach and change text displayed in messageboxes as well ?
help please ...
-- modified at 10:41 Friday 19th May, 2006
|
|
|
|
|
Hi!
Since MessageBoxes use the language of the Language Pack you're got installed for your .NET framework, I don't think this will be possible.
Regards,
mav
--
Black holes are the places where god divided by 0...
|
|
|
|
|
I’ve made some reports using the ReportViewer and Reports (*.rdlc-files) in visual studio 2005. I really enjoy the ReportViewer!! My reports is now generated direct from my SQL 2005 database but I now want to generate a report from a typed DataSet that is instantiated locally in the program (my typed dataset is a subset of info from the database).
How do I connect the .rdlc-file to my object? I see that I can choose Add new data source -> Object but I want in runtime to do that on my instantiated DataSet. Is that possible?
I for sure have missed something and all tips are welcomed!!
_____________________________
...and justice for all
APe
|
|
|
|
|
I have to print the contents of an html file (or stream) to a printer.
I've hunted around a bit and it seems I must use the graphics object to format my lines one at a time to send them to the printer.
In looking at some samples, this particular line of code seems to be common :
ev.Graphics.DrawString(line, printFont, Brushes.Black,
leftMargin, yPos, new StringFormat());
This is a concern to me, as my html has images in it. I dont believe I want to tell the DrawString what color to use.
Probably cause I'm new to dealing with this type of problem, I simply dont see what I really need to do.
Can someone point me to somthing that might help clear my head up?
To restate, I have HTML that I must (thru C# code) send to the windows installed default printer - I just dont see how-to!
Thanks!
-- modified at 10:20 Friday 19th May, 2006
Oh, in looking around some more I see it might be helpful to add that this HTML is being generated via XML/XSL transform inside a web service which has no visual components.
|
|
|
|
|
You could use a instance of the AxWebBrowser IE control. You have to have your HTML written to file somewhere, then navigate the IE control to it and use it to print the file.
private AxSHDocVw.AxWebBrowser axWebBrowser1;
private void Print() {
object o = null;
axWebBrowser1.Navigate(@"C:\print.html", ref o, ref o, ref o, ref o);
axWebBrowser1.ExecWB(
SHDocVw.OLECMDID.OLECMDID_PRINT,
SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER,
ref o, ref o
);
}
But if you are masochistic you can draw images with your Graphics object too. Not sure I'd be interested in writting my own HTML renderer.
|
|
|
|
|
Thanks - that helped me move forward a little. Apparently in 2005 you must use WebBrowser.
I tried...
WebBrowser webBrowserForPrinting = new WebBrowser();
webBrowserForPrinting.Visible = false;
webBrowserForPrinting.Url = new Uri(@"c:\\Checkpoint\\websites\\printservice\\app_data\\books.html");
while (webBrowserForPrinting.ReadyState != WebBrowserReadyState.Loaded)
{ };
webBrowserForPrinting.Print();
webBrowserForPrinting.Dispose();
I now get an error in a browser window:
System.Threading.ThreadStateException: ActiveX control '8856f961-340a-11d0-a96b-00c04fd705a2' cannot be instantiated because the current thread is not in a single-threaded apartment.
at System.Windows.Forms.WebBrowserBase..ctor(String clsidString)
at System.Windows.Forms.WebBrowser..ctor()
at Service.PrintXML()
Anyone have any good ideas as to what to do with this one?
As I said - its in a web service, I dont want the browser to be visible either.
Thanks!
|
|
|
|