|
|
execute your code in your mind assuming the textbox holds "abc", for two iterations, and you will know.
|
|
|
|
|
Or - and this is just a suggestion, so I'll whisper - use the debugger You might find it helps...
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
I'll pretend I didn't hear that.
IMO debuggers are fine for solving hard problems, just looking at the code and executing it mentally is what always has to come first.
|
|
|
|
|
I know what you mean, but sometimes I can stare at code and only see what I meant to write!
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
Why not use the built in methods?
if (e.KeyChar == 13)
{
if (Test1.Text.IndexOfAny(new char[]{'@', '.', ',', '!'}) < 0)
{
MessageBox.Show("The name can' t hold '.', '!', '[]'", "Info", 0, MessageBoxIcon.Error);
return;
}
if (Text1.Text != "")
{
ListBox1.Items.Add(Text1.Text);
}
Text1.Text = "";
}
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
|
Yep.
Now, I could say I left that as an exercise for the reader?
Or just admit it: I made a mistake - sorry!
Also, to work with your original code it needs to be:
if (e.KeyChar == 13)
{
if (Test1.Text.IndexOfAny(new char[]{'.', '!', '[', ']'}) >= 0)
{
MessageBox.Show("The name can't hold '.', '!', '[]'", "Info", 0, MessageBoxIcon.Error);
return;
}
if (Text1.Text != "")
{
ListBox1.Items.Add(Text1.Text);
}
Text1.Text = "";
}
because I added comma and atsign, and forgot your square brackets as well.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
why test after the unwanted characters have been added to the text? why not check them on entry, i.e. use the KeyDown event and refuse the characters. Or even override the IsInputChar() method.
|
|
|
|
|
Complicated - what happens if the user pastes it in?
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
Correct, one actually needs both kinds of validation to get immediate feedback.
IMO issuing a bad character message at the end of a line isn't part of a good UI.
|
|
|
|
|
Luc Pattyn wrote: issuing a bad character message at the end of a line isn't part of a good UI.
That throws most of t'interweb in the bin, then...
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
When updating a TreeView, I call BeginUpdate() before adding any nodes. Every now and again, when this is done the thread seems to halt and does not get past the BeginUpdate() call.
The problem is that this happens intermittently, thus sometimes I can spend 30mins trying to reproduce the problem, and it never happens, but other times it happens first attempt.
Has anyone seen this happen? or knows of a problem with BeginUpdate?
Regards,
Gareth.
(FKA gareth111)
|
|
|
|
|
Gareth H wrote: Has anyone seen this happen? or knows of a problem with BeginUpdate?
Any chance of BeginUpdate being called on a different thread?
|
|
|
|
|
No, since i do a If (InvokeRequired) at the top of the method.
Regards,
Gareth.
(FKA gareth111)
|
|
|
|
|
Hmm. There's one problem I've seen with InvokeRequired - it returns false if the control's underlying Win32 handle hasn't been created. And that happens if the control hasn't become visible yet.
|
|
|
|
|
The control is visible but not enabled.
Regards,
Gareth.
(FKA gareth111)
|
|
|
|
|
Hi Gareth,
I know your post is 3 month ago ... but I have the same problem seen right now.
I can fill the tree a hundred time with no problem and then it happens after the third call.
I didn't found a way to unlock the control - did you ?
Until a better idea is supplied I don't use BeginUpdate()
Regards,
Frank
|
|
|
|
|
Frank,
The problem with my code was that i was doing an:
If (InvokeRequired)
On the main control class, which always returned false when the problem occurred, but the actaul TreeView control was returned true for InvokeRequired.
Thus, the solution was to invoke on the TreeView control. If you need some more info, just say.
Regards,
Gareth.
(FKA gareth111)
|
|
|
|
|
Gareth,
thank you for your answer,
I see your problem was different, but I have the problem of a treeview lock when using BeginUpdate / EndUpdate.
My program worked 4 years without error under .NET 1.1 and I got the problems changing to .NET 2.0 SP1 - why ever.
I have nothing running in parallel tasks or threads which could interfere my program.
I left BeginUpdate / EndUpdate unused - no problem any more.
But that leaves no good feeling.
Regards,
Frank
|
|
|
|
|
Friends,
Im new to C#.. Using menustrip...
wants to open other form in main form itself, inspite of opening it in new.
code written in menu button
{
Attendence att = new Attendence();
att.Show();
}
This open form in new window.
|
|
|
|
|
It sounds like you want an MDI application. Set the Main Form's IsMdiContainer property to true, set the child form's MdiParent property to the MainForm before calling Show.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
private void sendSMSToolStripMenuItem1_Click(object sender, EventArgs e)
{
Attendence main = new Attendence();
main.ISPARENT// I DIDNT FIND THIS
main.Show();
}
|
|
|
|
|
MdiParent. Set the Attendence form's MdiParent property to the owner form. Set the owner form's IsMdiContainer property to true
|
|
|
|
|