【发布时间】:2012-01-02 22:31:22
【问题描述】:
我有一个带有绑定列表的 datagridvew,其数据源是一个交集表。我有另一个绑定列表,它充当查找并绑定到 DataGridViewComboBoxColumn 类型的列之一。我已经简化了绑定列表,如下所示:
public IList<Flight> flights = new List<Flight>()
{
new Flight { DepartureID = 1, DestinationID = 1, FlightNumber = "101" },
new Flight { DepartureID = 2, DestinationID = 2, FlightNumber = "202" },
new Flight { DepartureID = 3}
};
public IList<Departure> departures = new List<Departure>()
{
new Departure {ID = 1, City = "Toronto"},
new Departure {ID = 2, City = "Chicago"},
new Departure {ID = 3, City = "New York"}
};
public IList<Destination> destinations = new List<Destination>()
{
new Destination {ID = 1, City = "London"},
new Destination {ID = 2, City = "Paris"},
new Destination {ID = 3, City = "Amsterdam"}
};
我的 datagridview 中有五列:
- 出发ID:文本框
- 出发:文本框
- 目标 ID:文本框
- 目标:组合框
- 航班号:文本框
我有三个问题:
1) 出发是只读的。我想显示 ID 和城市。如何添加文本框以自动查找城市值。我想到了 OnCellPainting 事件并进行了查找,但 e.Value 是只读的。有没有类似 Delphi 的 OnCellDrawing 事件。
2) 在 Destinations 的组合框中,一旦用户从组合框中选择了一个值,我如何也更新 Destination ID?
3) 我如何处理我只有 Departure 值的情况(例如,此记录 (new Flight { DepartureID = 3}) 会引发无效值错误,因为组合框没有要查找的值)
【问题讨论】:
标签: c# winforms datagridview