|
OK, so lets say that the other dropdowns are named option1, option2, option3 etc. The following code will work for you:
<code>
private void Speciality_SelectedIndexChanged(object sender, System.EventArgs e)
{
select(Speciality.SelectedItem.Value.ToLower())
{
case "option 1":
option1.Visible = true;
break;
case "option 2":
option2.Visible = true;
break;
case "option 3":
option3.Visible = true;
break;
case "option 4":
option4.Visible = true;
break;
case "option 5":
option5.Visible = true;
break;
default:
break;
}
}
</code>
|
|
|
|
|
Keep in mind that if all of this is static, it would be better (and MUCH faster) to do this in Javascript so the items would not have to PostBack (and page flicker) in order to update the visibility of the dropdowns.
|
|
|
|
|
Its not allowing me to build the project with code like this? Im getting all sorts of build errors for missing ; and for the case text?
Thanks
Adam
|
|
|
|
|
The code that I wrote is not the actual code you should use, just an example of how to do it. Paste all of your code here and I'll fix your syntax for you.
|
|
|
|
|
Although syntactically my code is correct, are you sure you are using a c# code behind and not a VB.NET code behind? Also, did you paste exactly what I wrote?
|
|
|
|
|
Yes, im positive it is a c# code behind page.
I pasted exactly what you wrote in, but just changed the case values and visible panel names to that of what I am using. I have underlined where I am getting build errors
private void Speciality_SelectedIndexChanged(object sender, System.EventArgs e)
{
select(Speciality.SelectedItem.Value.ToLower())
{
case "Breast Surgery":
SpecialityBreastSurgery.Visible = true;
break;
case "Cardiology":
SpecialityCardiology.Visible = true;
break;
default:
break;
}
}
Many thanks
Adam
|
|
|
|
|
omg I'm so sorry... my mind was in VB.NET when I wrote this. (VB uses the keywork SELECT instead of SWITCH that is used in C#"
<code>
private void Speciality_SelectedIndexChanged(object sender, System.EventArgs e)
{
switch(Speciality.SelectedItem.Value.ToLower())
{
case "breast surgery":
SpecialityBreastSurgery.Visible = true;
break;
case "cardiology":
SpecialityCardiology.Visible = true;
break;
default:
break;
}
}
</code>
Also remember that your strings for your CASE statements MUST be all lowercase in this instance because I used a .ToLower() in the switch. (I have a habit of doing this to remove casing errors). If you want to use exact case, just simply remove the .ToLower() from the switch.
|
|
|
|
|
Hi there.
I have a form, with an Insert button. I also have a text field txtPassword, and another button next to it. The button is btnGeneratePswd. When I click on this button it calls a function Security.GeneratePaswd() and randomly generates my password, and inserts the value into the txtPassword. But when I click the generate the button, it does what the Insert button does, validate the controls, and does not create the password.
How do make the button create the password and populate the txtPassword textfield without triggering validation?
Regards,
Brendan
|
|
|
|
|
I assume by you saying that the button is automatically kicking off validation that this is an ASP.NET web page?
|
|
|
|
|
Yes, all that it must do is to generate a password, not kick off validation. The Insert button does that.
|
|
|
|
|
Ok, well then I'm also assuming that you're using the Web Validation controls provided by the .NEt Framework? If so, then you are most likely also using the default validation type of ClientSide. If all of this is the case then you can't choose which buttons you want to cause validation and which ones you don't. When client side validation controls are used the form auto validates any time a postback event is attempted. What you will need to do is change the Validation to "Custom" to allow server side validation so that you can tell the server in the code behind which controls to validate. I would google "Web Validation Controls" to get a better understanding of how they work before continuing.
|
|
|
|
|
for(int i=0; i<(players.Length*2); i++)
{
// Do something
// Update the view
updateview();
// Wait
}
I am building a small cardgame.
i give each player a card and then i want to wait for a few seconds before giving next user thier card.
Iam pretty new to C# and havent got any luck when i tested making a thread...
In short;
How can i make a loop that waits for example 3 sec before doing the next lap.
Mrnoname
|
|
|
|
|
System.Threading.Thread.Sleep will sleep the entire thread for x milliseconds before continuing. Keep in mind that if this code is running in your form, the form will not respond to any windows command for that 3 seconds. If you want this to work properly, you should run this block of code in a new thread.
One other way to do this (without locking up the form) is to create a timer instead of a loop.
See the code below:
<code>
private int currentPlayer = 0;
private System.Windows.Forms.Timer t = new Timer();
public void BeginSetupCards()
{
this.t.Interval = 3000;
this.t.Tick += new EventHandler(t_Tick);
}
private void t_Tick(object sender, EventArgs e)
{
updateview();
this.currentPlayer++;
if(this.currentPlayer >= (this.players.Length * 2))
{
this.t.Stop();
}
}
</code>
Keep in mind that there are much better ways of doing this (which are a little more advanced) such as custom threading or even better asynchronous methods. If you would like some examples of the more advanced methods, please reply and I'll be glad to show you.
|
|
|
|
|
XRaheemX wrote:
updateview(); // It's a bad idea to update the form view from within a timer. You should create an event delegate for the update and kick it off using Form.Invoke;
It actually is fine to update controls from the tick event of System.Windows.Forms.Timer, as the event handler runs on the message pump thread.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Thats right (now I remember ), while learning about events and threading I made myself think that the timer ran in a different thread so I could get used to the idea... guess that was a bad idea. lol
|
|
|
|
|
Keep in mind that there are much better ways of doing this (which are a little more advanced) such as custom threading or even better asynchronous methods. If you would like some examples of the more advanced methods, please reply and I'll be glad to show you.
Like to know how...
Tried thread.sleep(3000);
But the result was that the form dident show for 3 seconds... not what i had in mind
|
|
|
|
|
Use the a timer, the Windows.Forms.Timer should be fine. Start it after playing the first card, play the second and subsequent cards on the Timer.Tick event (you'll need to keep track of which card is supposed to be played) and when all the cards are played just stop the timer again.
|
|
|
|
|
I know you're just trying to help, but did you read the replies before you posted? This is exactly what I posted an hour ago...
|
|
|
|
|
Your message wasn't there when I posted mine. I saw it right afterwards.
I gave the same answer so why do you need to be such a jerk about it?
|
|
|
|
|
I wasn't being a jerk, hence me putting "I know you're just trying to help". I apologize for my post to you and retract what I said. What I am wondering though is why my post didn't show up on yours when it was a full hour before?? Perhaps the code project is running a little slow? In any case, my goal here is not to make enemies so I am truly sorry.
|
|
|
|
|
Hello,
Is there an equivelent IRR function in C#, to the one in VB? Does anyone knows of any resources, etc.. that will help me to write the IRR function in C#?
Thank you.
|
|
|
|
|
You don't have to rewrite it and it's not part of Visual Basic.NET (the language anyway). It's part of the Microsoft.VisualBasic namespace, in the Financial class. Just set a .NET reference to the Microsoft.VisualBasic.dll and import the namespace.
If you really want the source code for the function, you can use Lutz Roeder's .NET Reflector to see the source in C# or VB.NET.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Thanks, Great Help
How can I see the code using Lutz?
Thank you
|
|
|
|
|
Hi folks,
Can any one guide me for a way to change "Startup Type" of windows service in runtime. Any pointer will be of great help.
Thanks in advance.
Regards
Rajeev
|
|
|
|
|