|
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.
|
|
|
|
|
I just did a qick search of the www and found "http://www.xp-icons.com/". I do not know if this help you. I used google: "Windows XP icons". Of cource you already tried that, blast it. Microsoft is a confussing critter, at times they try to give you what you need (some what ofuscated), while at other times they seem to try and hide it.
INTP
|
|
|
|
|
Because most of these "icons" aren't really icons; they are contained within a bitmap resource that is used in a masked image list. If you open shell32.doo or shdocvw.dll, you'll see several bitmap resources of various sizes and resolutions. You can either keep these as a bitmap and specify the size of a single image and the transparency color in your ImageList , then use ImageList.Images.AddStrip which will create individual images from the bitmap resource. You can also do this yourself by opening the bitmap in a decent image editor, splitting the images, and masking the color yourself (or still use the transparency color in the ImageList ).
-----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 it possible to define and access a property as an array? I don't mean the "public <type> this[int index]", but something like this:
public string myStringProperty[int index]
{
get
{
return someFunction(index);
}
set
{
someVariable[index] = value;
}
}
Then, access it like this:
myStringProperty[x] = "abc";
Thanks!
Len
|
|
|
|
|
No, but if your property type is a list, the list itself will have an indexer. Just use a highly-coupled list (perhaps create a list, passing a reference to your object in question with things like someFunction and someVariable as internal members to the object.
In any case, this is a case for methods; what's wrong with methods?
-----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 was hoping to read from/write to the property like a typical variable. It's more flexible than creating methods to read and write.
Thanks anyway!
Len
|
|
|
|
|
Yeah, um, passing a parameter to an indexer property is SO much different that calling a method that takes the same parameter.
Even when using reflection these two things can be treated the same way since both PropertyInfo and MethodInfo derive from MemberInfo so using the MemberInfo abstract class makes it transparent.
Flexibility is in the design by the developer.
-----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-----
|
|
|
|
|
Hello, as you probably already know that I'm a n00b of C# and programming.
Here's what I want to make but I couldn't find any example to follow.
I want to make a windows form application, when you run the application it will launch a console/dos application with it, the windows form application will check every 60 seconds to see if the dos application is still running or not, if the dos application crashed the windows form application will relaunch the dos application, I also want to make a output box in the windows form application so whatever is displayed in the dos application will display in the windows form application's output box, and it would be nice if I can run the dos application within the windows form application, so it will save some taskbar space =^^=
Please don't tell me to go read MSDN Library, it's 2GB of files and I wouldn't even know where to start, just give me examples and tell tell me the syntax since I'm a n00b, but I'm pretty sure this isn't hard to do for you advanced C# programmers, so help a n00b out ^__^;
|
|
|
|
|
C# n00b wrote:
Please don't tell me to go read MSDN Library, it's 2GB of files and I wouldn't even know where to start
That's why it has a table of contents and a search facility.
C# n00b wrote:
just give me examples and tell tell me the syntax since I'm a n00b
And such you will always be, if you refuse to learn how to research things for yourself.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Take a look at the Process class in System.Diagnostics. You use the static method Process.Start to start a process. You can use the Process.WaitForExit to wait until it ends and launch it again if you'd like.
As far as redirecting the output of a console application, take a look at the ProcessStartInfo class that can be used as a parameter for the Start method. You can redirect standard output, input, and error from/to a console application using this class's various properties.
Process.Start will return an instance of the Process class, and if you set the ProcessStartInfo properties up, you can then use things like Process.StandardOutput as a stream to read out of.
I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
-David St. Hubbins
|
|
|
|
|
it would help if you can write some codes =^^=
I just started C# few days ago.
|
|
|
|
|
Have you done any programming before? You should probably start with simpler programs than this if you're new to programming. You should grab a book or look at sample programs and websites etc.
I once wrote a program to automate a console application (GPG) and I ended having to create threads to properly read the output of the program to avoid locking on reads of standard output. The threads brought on the need for syncrhonization objects. It's not the easiest task in the world.
Posting the code for all of this would probably do more harm than good if you're really wanting to learn. It would also be a pain for me to cut out the relevant sections and still give you something that compiles (since I'm guessing a snippet wouldn't do you any good).
In any event, if you post a program that launches another program and describe what's wrong with it, I'll take a look at it and get you further along.
I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
-David St. Hubbins
|
|
|
|
|
You can tell by reading my name that I'm a C# n00b and I haven't done any programming in the past, I heard start clean from C# would prevent you from getting bad habit, so here I am struggling through sam's teach yourself visual studio .net in 21 days =^^=
but I really want to make this program for my own personal use, it would help if you can give me more hint, so far I've only understand how to use Process.Start("dos.exe");
but I dunno how to make my program to check and see if the dos program is already started before it start the dos program, I tried to use if ... else but it give me error and say you can't use that in the if()
is there a way I can reach you where I can talk to you in instant msg or irc channel?
|
|
|
|
|