-1

I need help to fix my code:

for (int P = 0; P < DataGridView.Rows.Count - 0; P++)
{
  TNTDATADataContext Context = new TNTDATADataContext();
  var q = (from C in Context.Customers
           where C.Code == Code.Text && C.CompanyId == CompanyId
           join TP in Context.TourProgrammes on C.PackageId equals TP.Id
           select new { TP.DayId, TP.FromCityId, TP.ToCityId, TP.Programme }).First();
           DataGridViewComboBoxCell DaysComboBoxCell = (DataGridViewComboBoxCell)DataGridView.Rows[P].Cells[0];
           DaysComboBoxCell.Value = (object)q.DayId;
           DataGridViewComboBoxCell FromCityComboBoxCell = (DataGridViewComboBoxCell)DataGridView.Rows[P].Cells[1];
           FromCityComboBoxCell.Value = (object)q.FromCityId;
           DataGridViewComboBoxCell ToCityComboBoxCell = (DataGridViewComboBoxCell)DataGridView.Rows[P].Cells[2];
           ToCityComboBoxCell.Value = (object)q.ToCityId;
           DataGridView["Programme", P].Value = (object)q.Programme;
}

This code is working well and bind a single value in DataGridViewComboBoxCell which I have bind by code.

There is a first snapshot

first snapshot

There you can see a area of tour programme where are 3 DataGridViewComboBoxCell in a DataGridView this is a before loading Customer Detail Snapshot now I've load a Customer Tour Details after entering code in Customer Code TextBox Filed it showing all details but not showing rest of tour programme list in DataGridView its showing result in this second snapshot

second snapshot

I want a result like this third snapshot which I'm making manually for you can understand how can I want result after loading customer Tour detail's

third snapshot

halfer
  • 19,824
  • 17
  • 99
  • 186

1 Answers1

0
for (int P = 0; P < DataGridView.Rows.Count - 0; P++)

DataGridView.Rows.Count happens to be the row number of current DataGridView, and its value is 1.

Maybe you should get the row number from Context

Qin Tianyi
  • 71
  • 1
  • if i set the value 1 then DataGridView count was not working. which data you are seen in second snapshot that was coming after set value 0 in loop – omstackoverflow Nov 13 '15 at 14:38