Creating a loop around a checkedbox

Discussion in 'C#' started by firstoption, Sep 4, 2014.

  1. firstoption

    firstoption New Member

    Joined:
    Apr 1, 2014
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    0
    Good day to all,
    Please i need your support on how to modify the program below so that it can read the data(temperature value) sent from the microcontroller as long as the Checkbox is checked.At the moment the function
    Code:
    myFtdiDevice.Read(readData, numBytesToRead, ref numBytesRead);
           
    reads only the first temperature value sent from the microcontroller,the subsequent temperatue values are not being updated even though the Checkbox is still checked.I would be very glad if somebody could put me through on how to create a Loop as Long as the Checkbox is checked.Thank you for the usual Support.Best regards.




    Code:
    
    
     private void checkBox1_CheckedChanged(object sender, EventArgs e)
            {
                UInt32 numBytesRead = 0;
                UInt32 numBytesToRead = 1;
                byte[] readData = new byte[10];
    
               ftStatus = myFtdiDevice.Read(readData, numBytesToRead, ref numBytesRead);
            
               label11.Text = Convert.ToString(readData[0]);
         
            } 
    
    
    
     
  2. alia123

    alia123 New Member

    Joined:
    Jan 8, 2016
    Messages:
    65
    Likes Received:
    5
    Trophy Points:
    0
    Hey, try using this code :
    Code:
    var sList = "";
    $('input[type=checkbox]').each(function () {
        var sThisVal = (this.checked ? "1" : "0");
        sList += (sList=="" ? sThisVal : "," + sThisVal);
    });
    console.log (sList);
     
  3. Ami Desai

    Ami Desai Member

    Joined:
    Jan 5, 2017
    Messages:
    42
    Likes Received:
    17
    Trophy Points:
    8
    Location:
    Ahmedabad
    Home Page:
    http://www.ifourtechnolab.com/
    Hi,

    You can loop through the checkbox as follow

    Code:
    foreach (var control in this.Controls)
                {
                    if (control is CheckBox)
                    {
                        if (((CheckBox)control).Checked)
                        {
                            //update
                        }
                        else
                        {
                            //update another
                        }
                    }
                }
    Thanks
     
    shabbir likes this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice