【问题标题】:Issue in bind DataGridViewComboBoxCell in DataGridView在 DataGridView 中绑定 DataGridViewComboBoxCell 的问题
【发布时间】:2015-11-13 14:14:42
【问题描述】:

我需要帮助来修复我的代码:

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;
}

这段代码运行良好,并在我已通过代码绑定的 DataGridViewComboBoxCell 中绑定了一个值。

有第一个快照

在那里您可以看到一个旅游计划区域,其中 DataGridView 中有 3 个 DataGridViewComboBoxCell 这是加载客户详细信息之前的快照现在我在客户代码TextBox 中输入代码后加载了客户旅游详细信息 归档显示所有详细信息但未在 DataGridView 中显示其余的旅游节目列表,它在第二个快照中显示结果

我想要像我手动制作的第三个快照这样的结果,以便您了解在加载客户游览详细信息后我如何想要结果

【问题讨论】:

    标签: c# winforms linq datagridview datagridviewcomboboxcell


    【解决方案1】:
    for (int P = 0; P < DataGridView.Rows.Count - 0; P++)
    

    DataGridView.Rows.Count 恰好是当前DataGridView的行号,其值为1。

    也许你应该从Context获取行号

    【讨论】:

    • 如果我将值设置为 1,则 DataGridView 计数不起作用。您在第二个快照中看到的数据是在循环中设置值 0 之后出现的
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多