Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 20th, 2004, 12:14 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 119
Thanks: 0
Thanked 1 Time in 1 Post
Default Resetting Checkbox back to UNCHECKED

In the following method I want to be able clear the checkboxes if the user clicks on the NO button of the Yes/No dialog box to confirm deletion of the checked records:

private void btnDelete_Click(object sender, System.EventArgs e) {
    Cursor.Current = Cursors.WaitCursor;
    //Data source defined from invoicelist.cs
    DataTable chkInvoices;

       //Identify the variable to use in the loop below to identify the records checked.
    int Invoiceid = 0;

      //Build the criteria for the message box.
    StringBuilder InvoiceMsg = new StringBuilder();
    DialogResult returnButtonSel;
    chkInvoices = (DataTable)dataGrid1.DataSource;
    int cntChkInvoices = 0;
    while (cntChkInvoices < chkInvoices.Rows.Count)
    {
        if ((bool)chkInvoices.Rows[cntChkInvoices]["add"])
        {
            InvoiceMsg.Append(Convert.ToInt32(chkInvoices.Rows[cntChkInvoices]["invoiceid"]) + "\n\t" );
    }
    cntChkInvoices ++;
}

    if (InvoiceMsg.Length > 1)
        {
            returnButtonSel = System.Windows.Forms.MessageBox.Show(this,"Delete Checked Invoices?", "Confirm Delete", System.Windows.Forms.MessageBoxButtons.YesNo,Syste m.Windows.Forms.MessageBoxIcon.Warning);
        }
    else
        {
            returnButtonSel = MessageBox.Show("No Invoices Selected");
        }

    if( returnButtonSel == DialogResult.Yes)
    {
        //MessageBox.Show(returnButtonSel + "");
        cntChkInvoices = 0;
        while (cntChkInvoices < chkInvoices.Rows.Count)
            {
                if ((bool)chkInvoices.Rows[cntChkInvoices]["add"])
                {
                    Invoiceid = Convert.ToInt32(chkInvoices.Rows[cntChkInvoices]["invoiceid"]);
                    // Create new instance of the Invoice class from Invoice.cs
                    Invoice inv = new Invoice( Invoiceid, usersToken );
                }
                cntChkInvoices ++;
                }
                Load_Datagrid();
            }
            else
            {
                cntChkInvoices = 0;
                while (cntChkInvoices < chkInvoices.Rows.Count)
                {
                    chkInvoices.Rows[cntChkInvoices]["add"] = false;
                }
            }
        }

Any help or direction would be appreciated. Thank you.
 
Old July 21st, 2004, 11:05 AM
tnd tnd is offline
Authorized User
 
Join Date: Jun 2004
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Where are the checkboxes you want to uncheck? Can you highlight those in your codes? Also I see if( returnButtonSel == DialogResult.Yes) but I don't see an else or returnButtonSel == DialogResult.No. Where are you checking for No result? Please highlight those codes too.

 
Old July 21st, 2004, 12:24 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 119
Thanks: 0
Thanked 1 Time in 1 Post
Default

tnd,

Thanks so much for your reply. The code bolded and in red is my checkboxes. I have put in the else statement the code that I've tried and it does not work. Any suggestions would be appreciated.
 
Old July 21st, 2004, 01:41 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 119
Thanks: 0
Thanked 1 Time in 1 Post
Default

I finally fixed the problems with the help of a colleague. I forgot my cntChkInvoices ++ in my last while statement if the user clicked NO.

Thanks for the help anyway.





Similar Threads
Thread Thread Starter Forum Replies Last Post
checkbox checked by default by html:checkbox sachin.tathod Struts 3 December 4th, 2006 03:41 PM
Resetting DIVs based on stacking order keithc BOOK: Beginning CSS: Cascading Style Sheets for Web Design ISBN: 978-0-7645-7642-3 1 March 6th, 2006 03:32 PM
Resetting a form jbenson001 VB.NET 2002/2003 Basics 8 March 23rd, 2005 11:37 AM
Has checkbox been checked or unchecked? mat41 Javascript 4 December 8th, 2004 12:38 AM
history.back or hitting the back button won't work lian_a Classic ASP Basics 4 July 29th, 2004 12:14 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.