|
hey can you post a link to that?
I'm not an expert yet, but I play one at work. Yeah and here too.
|
|
|
|
|
Yes and no actually
The foreach statement repeats a group of embedded statements for each element in an array or an object collection. The foreach statement is used to iterate through the collection to get the desired information, but should not be used to change the contents of the collection to avoid unpredictable side effects. The statement takes the following form:
This doesnt mean you cant change the data in the elements of the collections just the contents of a collection.
Like so, if you add, delete, or sort the collection while inside an enumerator it will have un expected results for the simple fact that is an Enumerator and just grabs one time data. Much like modifying a pointer while iterating.
You can change the data inside the elements without it affecting them.
I have more than 20 classes linked to datagrids and use foreach to iterate through them and have not witnessed any unpredicted results yet. And besides all doc code shows ms using that especially in implementing collections.
Could use post a code example or detailed situation so I could try it and determine the root problem.
nick
I'm not an expert yet, but I play one at work. Yeah and here too.
|
|
|
|
|
It's clear. The error is only with computed fields, I send it some time ago to C#corner forum (it's now unusable). It's solved now. The reason is:
1. I created a table with about 400 fields dynamically.
2. I assigned Expression based on another fields to one of them:
dtBufor.Columns["aggr"].Expression="...";
3. I assigned null (or zer-length string) to this expression
4. After it getting from any table field was possible, but setting - sometimes impossible. Using dtBufor.Rows[rowno]["fieldname"] generated an immediate NullObjectReference error and dtBufor.Rows[rowno].ItemArray[fieldno] updated nothing without error
5. After setting Expression="0" it works (workaround).
6. See http://www.codeproject.com/script/comments/forums.asp?forumid=1649&mode=all&userid=56906&select=407524&df=100&app=50&fr=8305#xx407524xx
Hi,
AW
|
|
|
|
|
Hi,
A terrible mistake I formatted the wrong drive and along with it my C# project.. All I have is the release executable.. Is there any way I can re-engineer this back to my code.. I mean if it's in byte code...
Please Please help!!
|
|
|
|
|
Yes, you can, using Anakrino[^].
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
Hi.
I am trying to figure out how to find the appropriate icon for a specific file type (e.g. txt files), with out actually having a file to go by? I have tried the SHGetFileInfo, but that dont know when I dont have a file to get the information from. Can anyone help me?
Nightcrawler7514
Resistance is futile - Data (ST:First Contact)
|
|
|
|
|
Actually, this is about the only wait to do it if you want the information for a file that doesn't exist (without doing all the registry and icon handling yourself). It's easy to make work, though - I've used this alot. Below is an example:
public class FileInfo
{
private int const FILE_ATTRIBUTE_NORMAL = 0x80;
[DllImport("shell32.dll", CharSet=CharSet.Auto)]
private static extern IntPtr SHGetFileInfo(
string path,
int fileAttributes,
[MarshalAs(UnmanagedType.Struct), Out]out SHFileInfo info,
int fileInfoSize,
[MarshalAs(UnmanagedType.U4)]SHGFI flags);
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
private struct SHFileInfo
{
public IntPtr IconHandle;
public int IconIndex;
public int Attributes;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=260)]
public string DisplayName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=80)]
public string FileType;
}
[Flags]
private enum SHGFI
{
LargeIcon = 0x0,
SmallIcon = 0x1,
OpenIcon = 0x2,
ShallIconSize = 0x4,
PIDL = 0x08,
UseFileAttribute = 0x10,
AddOverlays = 0x20,
OverlayIndex = 0x40,
Icon = 0x0100,
DisplayName = 0x200,
TypeName = 0x400,
Attributes = 0x800,
IconLocation = 0x1000,
EXEType = 0x2000,
SysIconIndex = 0x4000,
LinkOverlay = 0x8000,
Selected = 0x10000,
AttrSpecified = 0x20000
}
public static bool GetFileInformation(string filename,
out string fileType, out Image fileImage)
{
SHFileInfo info = new SHFileInfo();
IntPtr retVal = SHGetFileInfo(filename, FILE_ATTRIBUTE_NORMAL,
out info, Marshal.SizeOf(typeof(SHFileInfo),
SHGFI.AddOverlays | SHGFI.DisplayName | SHGFI.Icon | SHGFI.SmallIcon
| SHGFI.TypeName | SHGFI.UseFileAttributes);
if (retVal != IntPtr.Zero)
{
fileType = info.FileType;
fileImage = Bitmap.FromHicon(info.IconHandle);
return true;
}
else return false;
}
} I just threw that together quick, so don't just copy and paste. You won't learn anything that way anyway. You had the right idea, but you must've been prototyping something wrong or forgetting about the marshaling stuff, whichis necessary is several cases in this example (such as pass-by-value strings).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
MAN.. I could kiss you. IT WORKED. I was actually on to it, but I can see where I made the mistake now. THANKS ALOT. You are a life saver.
Nightcrawler7514
Resistance is futile - Data (ST:First Contact)
|
|
|
|
|
Can anyone tell me how to trap the enter key on a windows form application? I want to call a function when the user hits enter. Also, can anyone tell me where I can find the ascii values for the keyboard keys.
Thanks
|
|
|
|
|
So many questions - so little time!
First, you can trap the Enter key with the keyboard events. You can capture the key with the KeyDown or KeyUp events on the Form , while setting Form.KeyPreview to true if you want it to receive notification of keyboard events from all controls (it's the parent HWND in the chain to be notified of messages if controls let them).
KeyUp would probably be better because it gives a (knowledgeable) user the chance to cancel the event with the Esc key.
Each of these events has a KeyEventArgs.KeyCode that corresponds to a Keys enumeration. You most likely shouldn't hardcode the ASCII key code because those can change with different codepages. .NET (and the Windows subsystem that drives it) takes a lot of this into account. Most likely the key code won't change for the Enter key, but why take the chance when it's so easy to just use the enumeration?
If you want the ASCII keys anyway (bad bad bad!) or for some other reason, just type "ASCII" into the help index - you know, the think you should've checked first. You'll see "ASCII character sets" (and many other links) that have the ASCII charts of 0-127 and 128-256.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Heath,
Thanks that was excatly what I was looking for!
|
|
|
|
|
Hi, just reading up on async delegates samples from MSDN.Reference:
".NET Framework Developer's Guide Asynchronous Delegates Programming Sample"
Some questions here, you guru can definitely explain this:
QUESTION 1:
Object state = new Object(); //What do we need this object for?
// Asynchronously invoke the Factorize method on pf.
IAsyncResult ar = fd.BeginInvoke(
factorizableNum,
ref temp,
ref temp,
cb, //Async callback delegate: invoke fc.FactorizedResults when pf.Factorize completes.
state); //What do we need this object for?
QUESTION 2:
I was expecting input parameter to WaitOne would be a Mutex or AutoResetEvent... etc:
AutoResetEvent e;
WaitHandle.WaitOne(e);
But instead, from our MSDN sample:
IAsyncResult ar = fd.BeginInvoke(
factorizableNum,
ref temp,
ref temp,
null,
null);
ar.AsyncWaitHandle.WaitOne(10000, false);
(2-a) I guess .NET framework signal a waitable handle encapsulated by IAsyncResult ar.. signaling it when fd delegate(s) completes. Is my understanding correct?
(2-b) What if there're more than one handler? Should I WaitAll instead?
ar.AsyncWaitHandle.WaitAll(10000, false);
That's it. Thanks.
norm
|
|
|
|
|
As the documentation states, the state can be anything you want to pass to the callback. This could be an array of Object , since every array is an Array and an Array inherits from Object (as everything in .NET does). I use a similar mechanism (my own delegates and callbacks, but same idea) to use generics while passing specifics to the callbacks. For instance, I provide a tree service that has many methods that all use the same "find node X" method that takes a callback and a state parameter. When the node is found, the callback is invoked and the state is passed as a parameter. The callback method uses the state to do the actual work. Each publicly exposed method needs to find a node in the same way, but the callback does something completely different and is specific to the exposed method - the state is data that is passed through from the exposed method to the callback method.
When talking of handles, it all comes down to threads. You could simply pass an EventArgs derivative because those are created in many threads - the handle that you wait on must be global, otherwise one thread won't sync with another thread. The WaitHandle is global to all threads and WaitOne merely waits for it to be signals. If you look at the documentation, WaitAll and WaitAny are actually static methods. You must pass an array of WaitHandle instances to them and they will wait appropriately. WaitOne can be an instance method because it just uses the global handle of the WaitHandle from which it's being called.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
In my application I want to be able to send mail with attachments.
By using the smptMail object I can add attachments by using a filedialog and then the code:
aMessage.Attachments.Add( new MailAttachment(VedleggTxtBox.Text,MailEncoding.Base64))
where the VedleggTxtBox.Text is set by whatever the user select.
Thats all good, but I want to put in a path to a document manually in the code instead of using a filedialog to automaticcaly set the value og Vedleggtxtbox.text.
Plz help..
Or could anyone direct me to a page or some code on how I do attachements by using Outlook in my application. I been searching a long time, and havent found a good example yet using c#.
|
|
|
|
|
Are you sure the path exists that you want to code? You should use File.Exists() before attaching it to be sure. Passing a string you typed and a string that you got from another call are not different to the application and the CLR whatsoever! Seriously - the CLR sees the same thing - it's a System.String .
Also, this doesn't use Outlook, but a simple SMTP mailer. If you use Outlook, you open a can of worms because then you must start interoping a lot of things, thereby bloating the application. You must also make sure that the user has a specific version of Outlook on their system, or make sure your app can handle different Outlook and Office API versions. If all you need to do is send mail, just stick with the simple SMTP mailer.
If you still want the Outlook functionality in your app, the .NET Framework SDK has several examples with Word and MSDN has many examples in VB.NET and C# (primarily VB.NET, unfortunately, but remember that all languages targeting the CLR use the SAME class library so most stuff is the same - just syntax is different).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Is there an easy way to determine which radio button in a group has been chosen, besides having to put code in the checkchanged or clicked event for each button in the group...???
thanks,
vince
|
|
|
|
|
Like in HTML? No, unfortunately. But it doesn't have to be difficult at all. The radio buttons must be in some container, be that any given Control or, typically, a GroupBox . In order for controls to show up in the UI, they must be added to the container's Controls collection. Use that to your advantage:
foreach (Control c in this.Controls)
{
RadioButton rb = c as RadioButton;
if (rb != null && rb.Checked)
{
Console.WriteLine("You selected {0}!", rb.Text);
break;
}
}
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
I need to make an application that reads from popular GIS file formats like ESRI Shape File or MapInfo TAB.
I found the open source GeoTools.net but they apparently don't work and the website on sourceforge is not really being updated.
Is there any open source or free library out there for use with .NET?
"Nelle cose del mondo non e' il sapere ma il volere che puo'."
|
|
|
|
|
Has any one had much luck with this.
I have run AXIMP ont the .OCX to create the DLL. Then i have registerd the DLL using REGASM.
I add a reference to the DLL, then try to instantiate an object, I get the following error
An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll
Additional information: Catastrophic failure
Has anyone any ideas.
I have also tried this by just adding a reference to the original .ocx, and letting the IDE to the AXIMP for me. Same problem.
Thanks
|
|
|
|
|
Big Trev wrote:
I have run AXIMP ont the .OCX to create the DLL. Then i have registerd the DLL using REGASM.
These two actions are doing the opposite.
If you intend to use an ActiveX control in your C# code, then use the IDE, Toolbox \ customize, and browse your ActiveX component. The ActiveX component will be preinteroped, so you don't need any manual call to aximp.exe
(this works in most cases. There are gotcha though).
When you drop the component into a form, you'll see whether it gets instantiated or not.
RSS feed
|
|
|
|
|
As Stephane said, just use the "Add Reference..." and select the COM tab. You almost have the right idea, though.
Use aximp.exe to import an ActiveX control and create an interop assembly. DO NOT, however, register it! Regasm.exe is for registering assemblies that contain interop metadata, such as controls that act as ActiveX controls through a CCW (COM-Callable Wrapper). If you use Regasm.exe on the interop assembly generated by from the native ActiveX control, you've just overwritten the registry settings so that the interop assembly is now the target of the CLSID! Any application trying to instantiate your original ActiveX control is now instantiating (unknowingly in almost all cases) the control in the .NET assembly through a CCW. The interop assembly, however, is looking for the actual control and not finding it because it's finding itself!
Now, I would hope (and don't remember off the top of my head) that regasm.exe checks to see if the assembly was imported from an ActiveX control. But it if isn't, you need to use "regasm.exe /u myassembly.dll" immediately, and then use "regsvr32.exe myactivex.ocx" to fix the registry problems that are most likely affecting you.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Thanks for the reply. I still can not get it working though.
this is the code i am using to create the object.
COMMSOCXLib.CommsOCXClass comm = new COMMSOCXLib.CommsOCXClass();
try
{
comm.Reset();
}
catch (System.Runtime.InteropServices.COMException e)
{
Console.WriteLine(e.ToString());
Console.ReadLine();
}
And this is the error i catch.
System.Runtime.InteropServices.COMException (0x8000FFFF): Catastrophic failure
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFla
gs flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at COMMSOCXLib.CommsOCXClass.Reset()
|
|
|
|
|
Did you unregister your interop assembly and re-register the actual ActiveX OCX? You might also re-install ActiveX control if it was packed in an installer, since the install might have written more registry entries. It seems as if the actual COM method (remember, the interop assembly is only a Runtime Callable Wrapper (RCW), in which calls are forwarded) is not being called because the forwarding method can't the object to call.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Yep, i did a regasm /u on the interop assembly, and regsvr32 on the ocx.
Still no joy.
let me know if you fancy having a go with the ocx. I can mail it. it is only 100k.
At the moment i an writing a DLL wrapper for the c api that also comes with the product.
Thanks
Trev
|
|
|
|
|
Hi all!
OK, so now I know how to use Office Primary Interop Assemblies to do Word automation, i.e. open a word document in its own window, maximize this window, toggle full screen mode, etc.
The question is: is it possible to load the document into the client area of a windows form? You know, if you open Microsoft Office documents in Internet Explorer they load into the explorer window, not into a blank window. Is this possible with Windows Forms / C#? If so, how?
Other - less important questions:
1) Is it possible to hide the caption (using automation) of the Microsoft Word when in full screen mode? The WordViewer doesn't show the caption in full screen mode, but the Word itself does.
2) Is it possible to force the Microsoft Word window to be always on top of other windows (again, using automation?)
3) Is it possible to use the Microsoft Word Viewer in a similar way? Whem I tried to browse the type libraries using oleview.exe I could find "Microsoft Word 9.0 Object Library", is there a type library for Word viewer?
Thanks in advance, any clues are highly appreciated!
Rado
|
|
|
|
|