Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. timer does not work

timer does not work

Scheduled Pinned Locked Moved C#
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    benjamin yap
    wrote on last edited by
    #1

    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

    M 1 Reply Last reply
    0
    • B benjamin yap

      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

      M Offline
      M Offline
      mav northwind
      wrote on last edited by
      #2

      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...

      B 1 Reply Last reply
      0
      • M mav northwind

        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...

        B Offline
        B Offline
        benjamin yap
        wrote on last edited by
        #3

        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

        S 1 Reply Last reply
        0
        • B benjamin yap

          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

          S Offline
          S Offline
          Seishin
          wrote on last edited by
          #4

          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!!!

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups