|
Can anyone help me? I`ve just started my adventure with .NET.
I want use regular expression in my text box to validate text. For example reg. expression like this : "[0-9][0-9]-[0-9][0-9][0-9]" accepts only for example "43-456" text. What if I enter "54-8f5" ? .NET Regular Expressions tells me that this text is not correct. But it doesn`t tell me which character is invalid.
My problem is that I want .NET Regular Expressions show me which character (which character index in this incorrect string) is invalid.
Can anyone help with this?
conrados
|
|
|
|
|
|
Hello all,
i am using Datagrid to dispay row directly from my database but i need to click on one row to open details for this row from another table in the database where i can hang the value for the row with specifc row like in the combobox ValueMember
Thanks for help
Hoho
|
|
|
|
|
DataRowView currentRowInTheGrid = (DataRowView)this.dataGrid1.BindingManager[this.dataGrid1.DataSource, this.dataGrid1.DataMember].Current;
I hope you understand...because is a rough world out there...
|
|
|
|
|
Thanks so much about your help
but i need to know the ID of this current record to select the related details with this ID.
thank
hoho
|
|
|
|
|
Having the dataRowView you can obtain the coresponding dataRow :
DataRowView currentRowInTheGrid = (DataRowView)this.dataGrid1.BindingManager[this.dataGrid1.DataSource, this.dataGrid1.DataMember].Current;
DataRow currentRow = currentRowInTheGrid.Row;
object myId = currentRow["myIdColumnName"];
I hope you understand...because is a rough world out there...
|
|
|
|
|
Alright, I'm writing a bunch of integers to the screen of different lengths, followed by other numbers.
Some are 3 digits long, some are five digits long, and the maximum is about 6 digits long.
If the number is less than 6 digits long, I want it to write extra spaces after the number, to make it 6 total characters, before displaying more data.
Etc.
How do I do this?
Thanks, As Always.
|
|
|
|
|
You should take a look at the Composite Formatting article on MSDN. It shows you the ins and outs of the process.
For your immediate satisfaction, though, try this:
String.Format( "{0,-6} {1,-6} {2,-6}", 7, 3.14, 0.5 );
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
-- modified at 19:58 Thursday 24th November, 2005
|
|
|
|
|
I have 1 quick question
Example:
if(!Page.IsPostBack)
{
}
OR
if(Page.IsPostBack == True)
{
}
does the compiler treat the above statments the same, or is one more efficient then the other, cpu cycles etc....
|
|
|
|
|
They are different, not because of the way that you've written them, but because the logic is different.
The first example, in pseudo code, says
IF PAGE IS NOT POSTBACK
While the second example, in pseudo code, says
IF PAGE IS POSTBACK
I wrote a wee program that tested both in release mode to see what the generated IL was:
if (isBlah)
{
Console.Write("It is Blah");
} became:
.maxstack 1
L_0000: ldarg.0
L_0001: brfalse.s L_000d
L_0003: ldstr "It is Blah"
L_0008: call void [mscorlib]System.Console::Write(string)
L_000d: ret
And
if (isBlah == true)
{
Console.Write("It is Blah");
} became:
.maxstack 1
L_0000: ldarg.0
L_0001: brfalse.s L_000d
L_0003: ldstr "It is Blah"
L_0008: call void [mscorlib]System.Console::Write(string)
L_000d: ret
So, you can see they are exactly the same thing. Which ever that you use is entirely up to you. What ever you feel more comfortable with the compiler will still turn it in to the same code.
Does this help?
My: Blog | Photos
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucious
|
|
|
|
|
I did another quick test to show
if(!isBlah) Vs. if (isBlah == false)
The result was code exactly the same length as before. So, even by adding in the ! (not) operator there is no performance difference.
So, it all comes down to what ever is most readable for you.
My: Blog | Photos
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucious
-- modified at 14:29 Thursday 24th November, 2005
|
|
|
|
|
|
This is my first time working with hashtables. Here's what I'm trying to do, and what I need to do.
First, I have a HashTable that's initialized with the capacity of 169 (the number of possible pocket hands in holdem poker).
I deal two random cards to a player - and then create a string that looks like this, from the cards:
AKo, AKs, KKo, 32s ... etc. It'll always be in that format.
Now, I have a hashtable called HandCounter.
What I want to do, is check if that string exists as a "key" in the hash table. If it does, then get the value from that key and increment the value that is stored by 1. If it doesn't, then create a new key/value pair with the pocket string as the key and the int value 1.
Here's what I thought the code would probably look like:
if(HandCounter.ContainsKey(Hand.ToPocketString()))
{
HandCounter[Hand.ToPocketString()]++;
}
else
{
HandCounter.Add(Hand.ToPocketString(), 1);
}
Though something is wrong here. I'm attempting to use a string as the key, but it says it requires a type of "object" for the key. I'm attempting to use the value as an integer, but it says it uses type "object" as the value as well.
Do I need to typecast these?
|
|
|
|
|
I just got this to work.
How do I enumerate through it, displaying the Key Value pairs?
|
|
|
|
|
Alright, i just figured that out as well:
foreach(string Key in HandCounter.keys)
Console.WriteLine(Key + ": " + HandCounter[Key].ToString());
Very simple, jeez.
|
|
|
|
|
i've searched these forums and google for this, ive found lots of questions about this, but no answers that worked for me. it would help if i could have an exact answer, because nothing ive found has helped me.
i have form1, when an item on a menu is clicked this code is called:
namespace.sendmessageform messageform = new namespace.sendmessageform();
messageform.ShowDialog(); the new form opens. when the form closes i need it to call a function on form1, how can i do this?
thanks in advance,
sam kline
-- modified at 12:52 Thursday 24th November, 2005
|
|
|
|
|
messageform will need a reference to form1 so you should either pass form into the constructor of sendmessageform or give sendmessageform a property where you can set form1:
public class sendmessageform : Form {
private form1 _otherForm;
public sendmessageform() {
...
}
public sendmessageform(form1 otherForm) : this() {
_otherForm = otherForm;
}
public form1 OtherForm{
get { return _otherForm; }
set { _otherForm = value; }
}
}
your code should then like either like
namespace.sendmessageform messageform = new namespace.sendmessageform(this);
messageform.ShowDialog();
or
namespace.sendmessageform messageform = new namespace.sendmessageform();
messageform.OtherForm = this;
messageform.ShowDialog();
|
|
|
|
|
it worked!
thanks a lot, you really helped me!
sam kline
|
|
|
|
|
I would like to provide an alternate point of view, if you don't mind. You don't have to call the method from messagefom . The ShowDialog method blocks the main thread until it returns. If you need to call the same function every time, then you could do something like this:
namespace.sendmessageform messageform = new namespace.sendmessageform();
messageform.ShowDialog();
this.callTheFunctionYouNeedToCall(); If you have more than one function that can get called, you could define a property in your sedmessageform that your main form can access to decide what to do next. For example,
namespace.sendmessageform messageform = new namespace.sendmessageform();
messageform.ShowDialog();
switch( messageform.SomeProperty )
{
case SomeEnum.Case1:
break;
case SomeEnum.Case2:
break;
} This design is more loosely coupled and does not require that your sendmessageform know about your main form. That would allow for better code re-use if you would like to use your sendmessageform again in another application or in another place in the same application.
I hope that helps you in some way.
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
i never knew that it blocked the main thread, it will definately help me some time. thanks for the tip.
sam kline
|
|
|
|
|
I have a question.
I have an assembly built in debug mode that I want to explore.
I wish to explore this assembly through Reflection, and at the break points, suspend execution and have a look around.
This can be done in VS.net, which is obviously well plugged into the CLR, but this has to also be possible outside the enviroment. Can this be done on code called by Reflection? Now i'm guessing that the whole breakpoint system is already built on reflection, so how is this done?
Cheers
Cata
|
|
|
|
|
|
Hello,
I'm having a problem with events, I did some tutorials and I guess I understand how to use them, but I can't get this piece of code to work...
I get a NullPointReference Exception :
......<br />
<br />
<br />
public delegate void MovementEventHandler();<br />
<br />
public class Beagle<br />
{<br />
private int x;<br />
private int y;<br />
public bool uptodate;<br />
<br />
public event MovementEventHandler Movement;<br />
<br />
public Beagle()<br />
{<br />
new Beagle(0,0);<br />
}<br />
<br />
public Beagle(int x, int y){<br />
<br />
<br />
this.x = x;<br />
this.y = y;<br />
<br />
Movement();<br />
}<br />
....<br />
}
Tnx in advance !
-- modified at 11:49 Thursday 24th November, 2005
|
|
|
|
|
sciamachy wrote:
public Beagle()
{
new Beagle(0,0);
}
Hmm, this allocates a new instance of the Beagle class without assigning it to anything. Unless this is a construct new to C# v2.0 that I'm not aware of, I don't think you're accomplishing anything. Someone help me out here, if I'm wrong.
To initialize your fields, you can do this:
public Beagle()
{
this.x = 0;
this.y = 0;
this.uptodate = true;
}
sciamachy wrote: // Update world
Movement();
Oops! You're raising the event without checking to see if it is null. If no one has yet subscribed to the event when you attempt to raise it, you'll get a null exception.
Better to do something like this:
protected virtual void OnMovement()
{
MovementEventHandler handler = Movement;
if(handler != null)
{
handler();
}
}
And call this method from elsewhere in your class when you need to raise the event.
|
|
|
|
|
Hello,
Is there a way of passing a dataset, or something like that, to populate a treeview, and not add a node at a time. And how to indicate in the dataset, or array the node hierarchy?
Thank you.
|
|
|
|