0
我在页面加载事件中填充我的组合框,如下所示。如何使用selectedindexchanged事件填充表单上的字段?
try
{
List<PreviousVersionData> listID = PreviousVersionData.getDatabase();
if (listID != null)
{
foreach (PreviousVersionData l in listID)
{
cmboBoxPreviousVersion.Items.Add(l.FormatID.ToString() + " - " + l.FormatName);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
该部分完美运行,但我想访问数据库来获取其余的相应字段,以便他们可以编辑。我想你可以用一种方法来获取基于选定值的数据。所选值为每个值返回null。我还为字段填充事件提供了我的代码。任何想法,为什么我得到一个空值,以及如何纠正这一点。也随时要求澄清或更多的信息。
if (cmboBoxPreviousVersion.SelectedValue != null)
{
PreviousVersionData pvdata = new PreviousVersionData();
pvdata = pvdata.getDataByID(cmboBoxPreviousVersion.SelectedValue.ToString());
Item.FormatID = pvdata.FormatID;
Item.FormatName = pvdata.FormatName;
Item.FormatDescription = pvdata.FormatDescription;
Item.StockID = pvdata.StockID;
Item.PrintPlantCode = (bool)pvdata.PrintPlantCode;
Item.PrintWeight = (bool)pvdata.PrintWeight;
Item.PrintPrice = (bool)pvdata.PrintPrice;
rChkBoxPlantCode.Checked = Item.PrintPlantCode;
rChkBoxPrintPrice.Checked = Item.PrintPrice;
rChkBoxWeight.Checked = Item.PrintWeight;
cmboBoxStock.Items.Add(Item.StockID);
rTxtBoxDescription.Text = Item.FormatDescription;
}
谢谢。