第一次发布,希望我没有复制已经问过的问题,我做了几次搜索,并多次重写我的代码无济于事。我的问题来自多个角度。关于我的程序的一些背景信息。多个控件与多个列表C#
我基本上是创建一个客户数据库,它存储Customer列表中Customer类型的对象和列表ReportList中类型InspectionReport类型的对象。然后我使用ListView来显示CustomerList Items的详细视图以供选择。从这一点,用户可以添加更多的客户,查看选定的客户,删除客户,添加报告和查看报告(一旦添加)。
我的问题是,一旦在ComboBox中选择了一个报告并被选中查看它就会在列表中查看错误的项目。
麻烦的地区我的代码中的如下:
private void ViewReportButton_Click(object sender, EventArgs e)
{
int selIndex = CustomerListView.SelectedIndices[0];
int selIndex2 = AvailableReportsDropDownBox.SelectedIndex;
tabControl.SelectedTab = tabInspReport;
populateViewReportTabOutputControls(selIndex, selIndex2);
activateViewReportTabOutputControls();
}
public void populateViewReportTabOutputControls(int selIndex2)
{
ViewCustNameLabel.Text = ReportList[selIndex2].getCustomerName();
ViewDateLabel.Text = Convert.ToString(ReportList[selIndex2].getInspectionDate());
ViewAddressLabel.Text = ReportList[selIndex2].getCustomerAddress();
AeratorStatusBox.Text = ReportList[selIndex2].getAeratorStatus();
FilterStatusBox.Text = ReportList[selIndex2].getFilterStatus();
HLAFloatStatusBox.Text = ReportList[selIndex2].getHLAFloatStatus();
OnOffFloatStatusBox.Text = ReportList[selIndex2].getOnOffFloatStatus();
SprayHeadStatusBox.Text = ReportList[selIndex2].getSprayHeadStatus();
SludgeLevelOutputBox.Text = Convert.ToString(ReportList[selIndex2].getSludgeLevel());
InspectorsNameOutputBox.Text = ReportList[selIndex2].getInpsectorName();
}
我想知道的是什么;是否有更好的方法来显示ComboBox中的选定项目,该项目将链接到特定的非数据绑定列表项目。
例如,我选择了客户[1],报告列表中有10个报告,其中4个属于所述客户,但是当我选择组合框中的第一个报告时,而不是给我来自ReportList [0]的Item,它给我说ReportList [4],这是所选客户的第一份报告。
在此先感谢。
,当你调用这个函数populateViewReportTabOutputControls你传递两个参数,并声明函数有一个参数,这意味着你传递错误的索引 –
呀,selIndex在方法调用不应该在那里,这是不重要的。它是从试图做别的事情。但我面临的问题是,使用selIndex2作为我的索引值,因为它与组合框中项目的索引相关,而不是项目在列表中的索引。我想要的可能是将组合框中的项目的索引与ReportList中它们各自的索引绑定的方式。 –
也许你应该通过跨越每一行并检查它的作用(特别是它处理的值)来调试你的代码。通过这种方式,你会发现你的指数不匹配的原因。 –