|
You could handle the Control.KeyDown event and use SendKeys.Send to send a tab:
this.myForm.KeyPreview = true;
this.myForm.KeyDown += new KeyEventHandler(this.myForm_KeyDown);
private void myForm_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
e.Handled = true;
SendKeys.Send("{TAB}");
}
} There's other ways through P/Invoking PostMessage , but doing it this way should work and keeps all your code managed.
-----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-----
|
|
|
|
|
Thank you for your reply.
I had tried this, but I tried it again (using the designer and adding the code to check: if(e.KeyCode == Keys.Enter) and what I found again was that this only seems to work if you place the _KeyDown check for each control rather than at the form level. Is there a way to trap the key stroke globally since setting the: [this.myForm.KeyPreview = true;this.myForm.KeyDown += new KeyEventHandler(this.myForm_KeyDown);] does not seem to do it?
|
|
|
|
|
That's why I included myForm.KeyPreview = true in my example code.
-----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-----
|
|
|
|
|
Thank you again for your response.
I tried as you suggested (the code you suggested is generated by the .NET studio by changing KeyPreview in the form properties to the "True" value) and the same result occured ... the return key was not trapped and the cursor did not advance to the next tab field. The following code was generated:
this.KeyPreview = true;
where "this" is the form.
When I changed the event handler for each field to access the function "GlAcctMaster_KeyDown", it worked fine. It generated the following code:
this.Text_Description.KeyDown += new System.Windows.Forms.KeyEventHandler(this.GlAcctMaster_KeyDown);
I much appreciate your responses.
|
|
|
|
|
Im looking for a way to unblock a Socket when then Accept() i called.... I´ve been looking at setSocketOption() but can´t get it to work.
Hope that someone can help me..
Thanks in advance
Søren Christensen
|
|
|
|
|
First use the SetSocketOption to have a timeout as such.
YOURSOCKET.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 10000);
(The third paramater is the timeout in Milliseconds)
Then put the Accept in a Try/Catch block because if it does time out it will cause a SocketException.
|
|
|
|
|
I´ve tried that, but it still doesn´t work, the exception is newer thrown...
<br />
listeningSocket.SetSocketOption( SocketOptionLevel.Socket, <br />
SocketOptionName.ReceiveTimeout, 10000 );<br />
<br />
try<br />
{<br />
connection = listeningSocket.Accept();<br />
}<br />
catch( SocketException )<br />
{<br />
}<br />
<br />
can you see any error?
Søren
|
|
|
|
|
I'm trying to make a call on a singleton remoting object
that is running using tcp channel.
I get the Transparent Proxy using Activator.GetObject
with no problems when I make the first call on the
remoting object.
This is part of the exception i get.
_remoteStackTraceString
=======================
_remoteStackTraceString "\nServer stack trace:
\n at
System.Runtime.Serialization.Formatters.Binary.BinaryAssem
blyInfo.GetAssembly()\r\n at
System.Runtime.Serialization.Formatters.Binary.ObjectReade
r.GetType(BinaryAssemblyInfo assemblyInfo, String name)
\r\n at
System.Runtime.Serialization.Formatters.Binary.ObjectMap..
ctor(String objectName, String[] memberNames,
BinaryTypeEnum[] binaryTypeEnumA, Object[]
typeInformationA, Int32[] memberAssemIds, ObjectReader
objectReader, Int32 objectId, BinaryAssemblyInfo
assemblyInfo, SizedArray assemIdToAssemblyTable)\r\n at
System.Runtime.Serialization.Formatters.Binary.ObjectMap.C
reate(String name, String[] memberNames, BinaryTypeEnum[]
binaryTypeEnumA, Object[] typeInformationA, Int32[]
memberAssemIds, ObjectReader objectReader, Int32
objectId, BinaryAssemblyInfo assemblyInfo, SizedArray
assemIdToAssemblyTable)\r\n at
System.Runtime.Serialization.Formatters.Binary.__BinaryPar
ser.ReadObjectWithMapTyped(BinaryObjectWithMapTyped
record)\r\n at
System.Runtime.Serialization.Formatters.Binary.__BinaryPar
ser.ReadObjectWithMapTyped(BinaryHeaderEnum
binaryHeaderEnum)\r\n at
System.Runtime.Serialization.Formatters.Binary.__BinaryPar
ser.Run()\r\n at
System.Runtime.Serialization.Formatters.Binary.ObjectReade
r.Deserialize(HeaderHandler handler, __BinaryParser
serParser, Boolean fCheck, IMethodCallMessage
methodCallMessage)\r\n at
System.Runtime.Serialization.Formatters.Binary.BinaryForma
tter.Deserialize(Stream serializationStream,
HeaderHandler handler, Boolean fCheck, IMethodCallMessage
methodCallMessage)\r\n at
System.Runtime.Remoting.Channels.CoreChannel.DeserializeBi
naryRequestMessage(String objectUri, Stream inputStream,
Boolean bStrictBinding, TypeFilterLevel securityLevel)
\r\n at
System.Runtime.Remoting.Channels.BinaryServerFormatterSink
..ProcessMessage(IServerChannelSinkStack sinkStack,
IMessage requestMsg, ITransportHeaders requestHeaders,
Stream requestStream, IMessage& responseMsg,
ITransportHeaders& responseHeaders, Stream&
responseStream)\n\nException rethrown at [0]: \n"
string
stackTraceString
================
_stackTraceString " at
System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMess
age(IMessage reqMsg, IMessage retMsg)\r\n at
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke
(MessageData& msgData, Int32 type)\r\n at
TAM.Data.Common.IPortal.Fetch(Object businessObject,
Object criteria)\r\n at TAM.Framework.Portal.Fetch
(Object businessObject, Object criteria) in
c:\\sourcecode\\tam\\tam.framework\\portal.cs:line 86"
string
_message
========
_message "Cannot find the assembly
TAM.BusinessObjects, Version=1.0.1424.15601,
Culture=neutral, PublicKeyToken=d3e3ed99c018e29a."
string
It keeps wanting to find the assembly that has the
BusinessObjects in even though I'm sending the object as
object type.
Is this a problem with my objects Deserialization or why
does the remoting need my assembly when it can get the
type from the object?
Any comments or help appreciated.
MickD
Mick D
|
|
|
|
|
When you use remoting you have to pass in the EXACT same copy of the class.
|
|
|
|
|
thanks.
ok, I have tried that (using the exact object) and it made no difference, from the exception that I still get. There is stack information against the property "_remoteStackTraceString" which presumably means that the object got to the remote object?? and cannot be unpacked (Deserialized). I cannot remember the sequence that remoting\channels performs when recieving information from another App domain.
Any comments or help appreciated
Mick D
|
|
|
|
|
Are you sure you are recieving the entire class before you try to Deserialize it because the TCP protocol has no bounds checking.
|
|
|
|
|
Hi,
can anybody tell me if what im doing here is correct?
Having 2 DataGrid Controls, one showing data from "ParentTable", the other showing data from "ChildTable", I am trying to synchronize them in a way that when I select a Row in the Child- DataGrid, the Parent- DataGrid should be updated too (dv2 is the DataView of the Parent-DataTable):
private void dataGrid1_CurrentCellChanged(object sender, System.EventArgs e)<br />
{<br />
CurrencyManager cm = (CurrencyManager)<br />
dataGrid1.BindingContext[dataGrid1.DataSource ,dataGrid1.DataMember];<br />
<br />
DataRowView drv = (DataRowView)cm.Current; <br />
// Set the RowFilter of the ParentTable-View to reflect changes in Child
<br />
dv2.RowFilter = "VERNR = '"+drv["VERNR"]+"'"; <br />
<br />
}
|
|
|
|
|
First, never concatenate strings like that - you incur serious performance penalties. In actuality, the CLR is creating a string to hold the first part, then creates a second string long enough to hold the first part and the second part, then copies each character from the first and second parts into the new string. Then it repeats this process with a third string. Those other two strings hang around until the GC picks them up. Instead, use String.Concat (string.Concat("VERNR = '", drv["VERNR"] as string, "'") or String.Format (string.Format("VERNR = '{0}'", drv["VERNR"]) ), which uses the StringBuilder internally.
Second, if you're using the code we talked about earlier, then the problem would seem to be in your call to get the CurrencyManager . If you are passing the Relation to the child's DataGrid.DataSource for the parent-child view, then you must pass that (and no DataMember ) when using the BindingContext property. See the docs for the BindingContext , which also mentions this constraint.
Also, you should debug your code and see if you're getting a value for drv["VERNR"] , which you should also cast to a string to be safe, or use the as keyword as I did above to be even more safe (it casts but doesn't throw an exception if the cast fails, it just returns null ).
-----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-----
|
|
|
|
|
Hi,
thanks for the hint on string concatenation, I am new to C# and not quite into the internals yet...
Heath Stewart wrote:
Second, if you're using the code we talked about earlier, then the problem would seem to be in your call to get the CurrencyManager. If you are passing the Relation to the child's DataGrid.DataSource for the parent-child view, then you must pass that (and no DataMember) when using the BindingContext property. See the docs for the BindingContext, which also mentions this constraint
I don't really know if I explained my issue right: The thing is I can't define some Binding where, when selecting some Item in the Child-View, the Parent-View gets updated:
Imagine having a Table with Products where some Column contains a Number being the Foreign-Key to another Table which holds the Vendor Information to any Product with this number as Primary-Key, so browsing through the Products, there should always be the Vendor displayed...
|
|
|
|
|
mgaerber wrote:
I am new to C# and not quite into the internals yet...
String manipulation is tasking in practically any language. Keep what I said in mind when doing anything with strings or other types of buffers.
mgaerber wrote:
I don't really know if I explained my issue right: The thing is I can't define some Binding where, when selecting some Item in the Child-View, the Parent-View gets updated:
You explained it fine, and I gave you one possibility as to what's wrong. The BindingContext contains data- or property-bindings for the control. If you have data-bound your child table to a control, a BindingContext is useful so long as you give it the same DataSource and DataMember that are specified in the control.
What you're doing is essentially right - you're getting a value and filtering the DataView of the parent DataGrid . You really need to debug your code, though - step through it and see if you're getting a value from your DataRowView before applying it to your filter. Stepping through your code and examining the Auto or Locals window should give you some idea of what you can use to get the values you need. I'm sorry I don't have more time to write and test this myself, but learning is the most important part and debugging certainly fosters that.
...but you are on the right track.
-----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-----
|
|
|
|
|
As you said: learning is the most important part...
But now I know that I am not doing something completely stupid and of course I will have t check for the right CurrencyManager and sourrounding the methods in question with some try/catch - clauses etc.
You really helped me a lot on this...
|
|
|
|
|
Does the compiler initialise the member variables when the compiler-created constructor is called? For example
<br />
class MyClass<br />
{<br />
public int mTinyInt<br />
{<br />
get { return mTinyInt; }<br />
set { mTinyInt = value; }<br />
}<br />
}<br />
<br />
MyClass MyObj = new MyClass();<br />
Console.WriteLine("\n\nThe int values is:\n {0}", mTinyInt);<br />
<br />
This however gives me a stack overflow. I would assume that the compiler would make all members 0 in the created constructor, but is this not so?
Obseve everything, remember more...
|
|
|
|
|
<br />
private int mTinyInt = 1;<br />
<br />
public int mPubRepTinyInt<br />
{<br />
get { return mTinyInt; }<br />
set { mTinyInt = value; }<br />
}<br />
So when I want to use mTinyInt I actually call mPubRepTinyInt. This cannot be right surely - where am I going wrong?
Obseve everything, remember more...
|
|
|
|
|
Ok I've got it now, they are properties and I access the actual members using them.
I saw an example about a Person class, a Name property, and a myName member variable on the MSDN site. I'm not sure why all this is necessary (the best reason I've seen on MSDN is b/c it gives a nice 'clean' look to the code. wtf? Better than Person.mPersonName = "John" - is it not down to how you name your variables?).
Thanks to everyone who had a look at this.
Obseve everything, remember more...
|
|
|
|
|
Because properties allow you to perform validation and other useful functions, where fields cannot. Lets say your Person class has an Age property (in actuality, it's better to store their birthday, but this is only an example...). You could use a UInt16 or something, but unsigned integers are not CLS-compliant. So, you want to make sure that only a positive integer is passed to the Age property:
public class Person
{
private int age;
public int Age
{
get { return this.age; }
set
{
if (value <= 0) throw new ArgumentException();
this.age = value;
}
} This is used a lot throughout the .NET Framework and in many other applications, even in non-.NET applications (like in VB, Java Beans, JScript, etc.).
If also allows you to control member access. If you use fields, you can't control whether other classes can write to it (you could use the readonly keyword, but then your field can only be initialized in the static or an instance constructor, which isn't always desired. To do this, you merely use the get accessor and don't use the set accessor (so other code can't change it via that property). There is many, many reasons to use properties over fields.
-----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-----
|
|
|
|
|
Hey that makes sense. Thanks, I'll refer to what you said while I'm learning C#.
Obseve everything, remember more...
|
|
|
|
|
See how good CP is? Almost so good, it can help yourself
leppie::AllocCPArticle("Zee blog"); Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.
|
|
|
|
|
I have a question about how to hook API with the C# onely.
We know we can use vc++ to create DLL .
if we want to hook API ,we must use the ASM in our code.
We can use ASM in vc++.So we can hook API.
but how can we use ASM in C#?
|
|
|
|
|
If your talking about Windows hooks there is a good article at
http://msdn.microsoft.com/msdnmag/issues/02/10/CuttingEdge/default.aspx
|
|
|
|
|
Does anyone know where to download Windows XP common icons, such as cut, copy, delete, etc.
Microsoft stated in the Window XP Design Guidelines that they would provide them in the future, that was 2001.
I have already tried using a icon extracter, however the common icons aren't stored as resource icons.
|
|
|
|
|