|
Check the state of the checkbox and use the appropriate operator.
if(checkbox1.checked)
price += Convert.ToDouble(dgw.Cells[6].Value.ToString());
else
price -= Convert.ToDouble(dgw.Cells[6].Value.ToString());
Just because we can; does not mean we should.
|
|
|
|
|
What problem are you having?
One problem I can see is that you don't have any logic listed to do the price subtraction.
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Individuality is fine, as long as we do it together - F. Burns
|
|
|
|
|
You are missing code for when the checkbox is false. Look at the else clause that you have been shown...
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
How do change the properties of tool in Form1 from other Form2?
|
|
|
|
|
Via a delegate, I guess.
Christian Graus
No longer a Microsoft MVP, but still happy to answer your questions.
|
|
|
|
|
You can use a get if your initializing Form2 from Form1, and using Form2 as a Dialog.
For example:
private string _PropertyValue;
public string PropertyValue
{
get{return _PropertyValue;}
}
private void ShowForm2()
{
Form2 f2 = new Form2();
if(f2.DialogResult = DialogResult.OK)
{
property.value = f2.PropertyValue;
}
}
You would need to set up Form2 with dialog returning properties. Be wary that this answer might not be appropriate for your case.
|
|
|
|
|
use "passing data between form" in search textbox. you have several articles!
good luck
|
|
|
|
|
Hi, how do i empty every object inside my hashtable
|
|
|
|
|
I would guess that you can Clear the Keys property. Assuming the hashtable doesn't have an overall Clear method, like the other containers do.
Christian Graus
No longer a Microsoft MVP, but still happy to answer your questions.
|
|
|
|
|
Hashtable ht = new Hashtable();
ht.Clear();
Try just typing your variable plus .
ht.
and look through the options. Its usually in front of you.
Hogan
|
|
|
|
|
hi,
let suppose ,there are 10 combobox in a windows application form ,i want set the selected.index= 0 of all combobox by foreach loop.....i have try but fail
|
|
|
|
|
foreach(Control c in Controls)
{
ComboBox cb = c as ComboBox;
if (cb != null)
cb.SelectedIndex = 0;
}
Christian Graus
No longer a Microsoft MVP, but still happy to answer your questions.
|
|
|
|
|
hi,
when i use youe coding without if(cb!=null) then an error occur......why?
i confuse because combobox collections has some data....
|
|
|
|
|
You're selecting all the controls, but not all of them will be a combobox. With the check for null, you're making sure that the object you just MADE a combobox, was really a combobox to begin with
|
|
|
|
|
but i declare first ... ComboBox cmb = c as ComboBox;.then why we confirm either it is combobox or not
|
|
|
|
|
foreach(Control c in Controls)
{
ComboBox cb = c as ComboBox;
if (cb != null)
cb.SelectedIndex = 0;
}
this loops through ALL the controls on the current form, that's buttons, checkboxs, textboxes etc. There are a lot of controls on a form. So, as you're looping through, if you try and treat an object that is NOT a checkbox like a checkbox, it will error. Soooooo.... you test to see if the conversion to ComboBox worked. You can't easily select JUST ComboBoxes from a form, you have to go through the controls.
|
|
|
|
|
Thanks.....important thing is "ComboBox cb = c as ComboBox;" if c is not combobox then cb.SelectedIndex = 0; would be fail.........
thanks again....
|
|
|
|
|
|
"public void DisplayMessage(Object myReactor, MeltdownEventArgs myMEA)
{
//FormReactor FR = new FormReactor();
String message = myMEA.Message;
delegateReactorMessage(FR.listBoxReactor, message);
}"
First, your delegate doesn't need to conform to the object/eventargs model, it can have any signature.
Second, it looks like you're trying to pass the listbox to the delegate. Why ? That misses the whole point. The point is, your delegate method should fire in the scope of the listbox, and the code to work with the listbox should run locally. If you're going to pass the listbox, the code could be anywhere, so why use delegates ?
Christian Graus
No longer a Microsoft MVP, but still happy to answer your questions.
|
|
|
|
|
Thanks, but even so when I start the program it still doesn't pass on the message, start button activtes the begin button whic should send a message a that is not happening whether I use a delegate or not, yet the begin button will load a message.
Michael
|
|
|
|
|
What do you see in the debugger ?
Christian Graus
No longer a Microsoft MVP, but still happy to answer your questions.
|
|
|
|
|
Everything compiles and runs but nothing happens when the delegate runs the buttonBegin, I expected to see "Start Reactor" as I would when I click on the button itself. Here is an updated copy, which is what I originally had before playing with it to try different ideas.
Thanks,
Michael
namespace ReactorDelegates
{
public delegate void DelegateReactorMessage(String message);
public delegate void DelegatebuttonStart_Click(object sender, EventArgs e);
public delegate void DelegatebuttonBegin_Click(object sender, EventArgs e);
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
public static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FormStartReactor());
//new FormReactor(),
}
}
namespace ReactorDelegates
{
public partial class FormStartReactor : Form
{
static FormReactor FR = new FormReactor();
Action<String> delegateReactorMessage = FR.ReactorMessage;
DelegatebuttonBegin_Click delegatebuttonBegin = new DelegatebuttonBegin_Click(FR.buttonBegin_Click);
public FormStartReactor()
{
InitializeComponent();
}
public void buttonStart_Click(object sender, EventArgs e)
{
FormReactor FR = new FormReactor();
Reactor myReactor = new Reactor();
ReactorMonitor myReactorMonitor = new ReactorMonitor(myReactor);
reactorToolStripMenuItem_Click(sender, e);
delegatebuttonBegin(sender, e);
// Set myReactor to 100 degrees Celcius
delegateReactorMessage("Setting reactor temperature to 100 degrees Celcius");
myReactor.Temperature = 100;
// Set myReactor to 500 degrees Celcius
delegateReactorMessage("Setting reactor temperature to 1500 degrees Celcius");
myReactor.Temperature = 1500;
// Set myReactor to 2000 degrees Celcius
delegateReactorMessage("Setting reactor temperature to 3000 degrees Celcius");
myReactor.Temperature = 3000;
}
private void reactorToolStripMenuItem_Click(object sender, EventArgs e)
{
FormReactor mdiChildForm = new FormReactor();
mdiChildForm.MdiParent = this;
mdiChildForm.Show();
}
}
}
namespace ReactorDelegates
{
public partial class FormReactor : Form
{
public FormReactor()
{
InitializeComponent();
this.listBoxReactor.Items.Clear();
this.listBoxReactor.Items.AddRange(new object[] {"Reactor down"});
}
public void ReactorMessage(String message)
{
listBoxReactor.BeginUpdate();
listBoxReactor.Items.Add(message);
listBoxReactor.EndUpdate();
}
public void buttonBegin_Click(object sender, EventArgs e)
{
ReactorMessage("Start Reactor");
}
}
}
namespace ReactorDelegates
{
class ReactorMonitor
{
static FormReactor FR = new FormReactor();
Action<String> delegateReactorMessage = FR.ReactorMessage;
public ReactorMonitor(Reactor myReactor)
{
myReactor.OnMeltdown += new Reactor.MeltdownHandler(DisplayMessage);
}
public void DisplayMessage(Object myReactor, MeltdownEventArgs myMEA)
{
String message = myMEA.Message;
delegateReactorMessage(message);
}
}
}
namespace ReactorDelegates
{
class Reactor
{
Int32 temperature;
String strReactorMessage;
public delegate void MeltdownHandler(Object reactor, MeltdownEventArgs myMEA);
public event MeltdownHandler OnMeltdown;
public Int32 Temperature
{
set
{
temperature = value;
if (temperature > 1000)
{
if (temperature < 2000)
{
strReactorMessage = "Reactor meltdown in progress";
}
else
{
strReactorMessage = "The reactor is critical, YOU ARE DEAD, DEAD, DEAD";
}
MeltdownEventArgs myMEA = new MeltdownEventArgs(strReactorMessage);
OnMeltdown(this, myMEA);
}
}
}
}
}
namespace ReactorDelegates
{
class MeltdownEventArgs : EventArgs
{
String message;
public MeltdownEventArgs(String message)
{
this.message = message;
}
public String Message
{
get
{
return message;
}
}
}
}
|
|
|
|
|
I am using Syste.Collections.Generic.List
I made just a test and noticed that it can ran out of memory with large entrys. Is there a whay to handle "unlimited numbers" of its content.
Is there a diffrent whay to handle arrays with faster accsess without predefineing its array size?
does "delete" command free memory without waiting to get destroyed by Garbage Collectors?
|
|
|
|
|
Saksida Bojan wrote: noticed that it can ran out of memory with large entrys
No, your program ran out of memory. The list will work so long as you have memory for your app.
Christian Graus
No longer a Microsoft MVP, but still happy to answer your questions.
|
|
|
|
|
Is there a whay of increasing App Memory or shoud i resort to I/O Accsess?
|
|
|
|