timer does not work
-
hi, i have a timer which call this method CalPrice(). The calprice will check the dategridview first column if the checkbox ==true, then calculate the price base on the the other column
private void CalPrice()
{
double price = 0.0;
foreach (DataGridViewRow dgw in dataGridProduct.Rows)
{
DataGridViewCheckBoxCell datacell = dgw.Cells[0] as DataGridViewCheckBoxCell;try { if ((bool)datacell.Value == true) { //MessageBox.Show("" + dgw.ToString()); price += Convert.ToDouble(dgw.Cells\[6\].Value.ToString()); } lblTotalPrice.Text = "Total Price : $ " + price; } catch (Exception exc) { } } private void timer1\_Tick(object sender, EventArgs e) { CalPrice(); } }
I have set the timer to enable and interval to 1000(1 second). But when i load the form, the timer dont seems to start. It does not call the calPrice method
-
hi, i have a timer which call this method CalPrice(). The calprice will check the dategridview first column if the checkbox ==true, then calculate the price base on the the other column
private void CalPrice()
{
double price = 0.0;
foreach (DataGridViewRow dgw in dataGridProduct.Rows)
{
DataGridViewCheckBoxCell datacell = dgw.Cells[0] as DataGridViewCheckBoxCell;try { if ((bool)datacell.Value == true) { //MessageBox.Show("" + dgw.ToString()); price += Convert.ToDouble(dgw.Cells\[6\].Value.ToString()); } lblTotalPrice.Text = "Total Price : $ " + price; } catch (Exception exc) { } } private void timer1\_Tick(object sender, EventArgs e) { CalPrice(); } }
I have set the timer to enable and interval to 1000(1 second). But when i load the form, the timer dont seems to start. It does not call the calPrice method
Hi! Did you debug or are you just assuming that CalPrice is not being called? If you're simply swallowing any exception that's being thrown, you can come to false conclusions. Apart from that you either didn't assign an event handler for Tick or you didn't start the timer - not much else that can go wrong. Timers work just fine for a lot of people out there, you know... :)
Regards, mav -- Black holes are the places where God divided by 0...
-
Hi! Did you debug or are you just assuming that CalPrice is not being called? If you're simply swallowing any exception that's being thrown, you can come to false conclusions. Apart from that you either didn't assign an event handler for Tick or you didn't start the timer - not much else that can go wrong. Timers work just fine for a lot of people out there, you know... :)
Regards, mav -- Black holes are the places where God divided by 0...
which event should i use to check if the column is tick or untick in a datagrid. i tried cell_click but after i tick a checkbox, i have to click OUt of the datagrid, then it will populate the price
-
which event should i use to check if the column is tick or untick in a datagrid. i tried cell_click but after i tick a checkbox, i have to click OUt of the datagrid, then it will populate the price
Maybe grid's CellValueChanged event - in the event arguments you get the index of the edited row and column index as well.. it's called when the value is commited ex. when the editmode is set to 'doubleclick or f2' [entar] commits value change. also when you use Convert.To... you don't have to use ToString() on the converted object.
life is study!!!