Click here to Skip to main content
15,893,663 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
What is an error in this code?

C#
if (cmbOctroi.Text == "Yes")
{
   for (int i = 0; i < dataGridView1.Rows.Count; i++)
   {
      if (dataGridView1.Rows[i].Cells["OctroiCode"].Value != null)
      {
         MessageBox.Show("Please select octroi Code");
         dataGridView1.Rows[i].Cells["OctroiCode"].Selected = true;
         return;
      }
   }
}
ExportPdf();


Here code running on button click event.
My ExporttPdf() is not running.

Thanks

Ankit Agarwal
Software Engineer
Posted
Updated 3-Jan-13 23:17pm
v3
Comments
Philip Stuyck 4-Jan-13 2:55am    
Totally unclear to me what is going wrong. What is exportpdf. Is that the code that you are posting ? That would mean that the code is simply not called. So you did not post the code containing the error.

1 solution

Modify as fallows
C#
if (dataGridView1.Rows[i].Cells["OctroiCode"].Value == null)//(dataGridView1.Rows[i].Cells["OctroiCode"].Value != null)
                       {
                           MessageBox.Show("Please select octroi Code");
                           dataGridView1.Rows[i].Cells["OctroiCode"].Selected = true;
                           return;
                       }


The main problem is return line where your function execution get ended.
 
Share this answer
 
v2
Comments
hemantkulshrestha 4-Jan-13 3:47am    
In for loop you are validating that OctroiCode should have a value otherwise you are prompting a message and returns from the function, correct me if I am wrong.
So it seems that your ExportPDF function must have some problem so you should provide the code of that.
[no name] 4-Jan-13 3:51am    
If datagridviewcombobox column is null so,that should be generate error (MessageBox.Show("Please select octroi Code");
If not null than execute the function ExportPdf();, but problem is- If comboboxcolumn not null sot that was generating an error msg (It's a wrong).
[no name] 4-Jan-13 3:52am    
If datagridviewcombobox column is null so,that should be generate error (MessageBox.Show("Please select octroi Code");
If not null than execute the function ExportPdf();, but problem is- If comboboxcolumn not null so that was generating an error msg (MessageBox.Show("Please select octroi Code")(It's a wrong).
Jibesh 6-Jan-13 4:15am    
Please update your question with some more details in addition to your comments provided here. for better result
Suvabrata Roy 4-Jan-13 4:02am    
Thanks Ankit,

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900