Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i m using datagridview with listbox control ............... i used the below code for binding data from table to a datagridview column....
C#
public void getGvDetailsIntoTable1()
       {
           try
           {
               int x = newDataGridView1.Rows.Count;

               for (int i = 0; i <=x-1; i++)
               {

                   QuotGridDetails1.Rows[i]["QuotationId"] = txtQuotationId.Text.Trim().ToString();
                   QuotGridDetails1.Rows[i]["QuotationDetailsId"] = dGridDetails.Rows[i].Cells["QuotationDetailsId"].Value;
                   QuotGridDetails1.Rows[i]["ItemDescription1"] = dGridDetails.Rows[i].Cells["ItemDescription1"].Value;
                   QuotGridDetails1.Rows[i]["Range1"] = dGridDetails.Rows[i].Cells["Range1"].Value;
                   QuotGridDetails1.Rows[i]["LeastCount1"] = dGridDetails.Rows[i].Cells["LeastCount1"].Value;
               }
           }
           catch (Exception ee)
           {
               MessageBox.Show(ee.Message);
           }
       }

While Executing these Statement i M Getting error like
There is no row at Position 0
.Any Solution Please.............
Posted
Updated 4-Jan-12 18:03pm
v2
Comments
Sergey Alexandrovich Kryukov 5-Jan-12 0:16am    
Please do not re-post!
--SA

1 solution

The error says that that no results were returned from your query. Put your code block in if condition. something like..

C#
if (newDataGridView1.Rows.Length > 0)
{
}
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 5-Jan-12 0:13am    
Simple, isn't it? My 5.
--SA

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