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 February 19th, 2004, 08:50 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 119
Thanks: 0
Thanked 1 Time in 1 Post
Default Error while trying to determine state of checkbox

In trying to determine if the checkboxes are checked within my windows form datagrid, I am trying to communicate to the user what records they will be deleting. My code is below, however the bolded stated is what is giving me an error which is stated below this code in red. Any direction or help would be appreciated. Thank you.

Here is my code and the error following:

private void btnDelete_Click(object sender, System.EventArgs e)
{
Cursor.Current = Cursors.WaitCursor;
DataTable chkInvoices;
Invoice inv = null;

StringBuilder InvoiceMsg = new StringBuilder();
int returnButtonSel = 0;
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,"The following invoice ID's will be deleted:\n\n\t" +InvoiceMsg.ToString(), "Confirm Delete", System.Windows.Forms.MessageBoxButtons.YesNo,Syste m.Windows.Forms.MessageBoxIcon.Warning);
    }
else
{
    MessageBox.Show("No Invoices Selected");
}
MessageBox.Show(returnButtonSel + "");
}

Error on bolded statement above:

Cannot implicitly convert type 'System.Windows.Forms.DialogResult' to 'int'
 
Old February 19th, 2004, 09:24 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

The MessageBox.Show method does not return an Integer, but a Dialog result. That is also what the error message is telling you.

Store the result of the Show method in a variable of type DialogResult, like this:
Code:
DialogResult myResult = MessageBox.Show("Are you sure?", "Quit?", MessageBoxButtons.YesNo);
if (myResult == DialogResult.Yes)
{
  MessageBox.Show("Yes");
}
else
{
  MessageBox.Show("No");
}
HtH,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old February 19th, 2004, 09:36 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 119
Thanks: 0
Thanked 1 Time in 1 Post
Default

Imar,

Thank you very much. Your time and response are appreciated. I'll try it.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Session state error shoakat ASP.NET 2.0 Professional 9 July 26th, 2007 12:09 PM
Checkbox state cq_ted ASP.NET 1.x and 2.0 Application Design 0 May 9th, 2006 12:56 AM
saving checkbox state in template column texasraven ASP.NET 1.x and 2.0 Application Design 7 September 28th, 2005 01:18 PM
State of CheckBox in ItemTemplate of DataGrid bpgadhia Classic ASP Professional 1 August 19th, 2004 01:26 AM
Need Help: Can't determine cause of error xgbnow Visual C++ 3 September 22nd, 2003 05:00 PM





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