我有一个在表单加载事件中填充的组合框。当然,这些值是字符串格式。他们的信息在组合框中显示为 1-info。我想取第一个数字并将其与数据库中的值进行比较。根据它找到的值,然后填充表单上的字段。这是我到目前为止所拥有的。我已经能够弄清楚将它转换回int 32。
if (cmboBoxPreviousVersion.SelectedItem != null)
{
string[] s = cmboBoxPreviousVersion.Items[cmboBoxPreviousVersion.SelectedIndex].ToString().Split(' ');
int id = Convert.ToInt32(s[0]);
Item.FormatID = data.FormatID;
Item.FormatName = data.FormatName;
Item.FormatDescription = data.FormatDescription;
Item.StockID = data.StockID;
Item.PrintPlantCode = (bool)data.PrintPlantCode;
Item.PrintWeight = (bool)data.PrintWeight;
Item.PrintPrice = (bool)data.PrintPrice;
rChkBoxPlantCode.Checked = Item.PrintPlantCode;
rChkBoxPrintPrice.Checked = Item.PrintPrice;
rChkBoxWeight.Checked = Item.PrintWeight;
cmboBoxStock.Items.Add(Item.StockID);
rTxtBoxDescription.Text = Item.FormatDescription;
}
rChkBoxPlantCode.Enabled = false;
rChkBoxPrintPrice.Enabled = false;
rChkBoxWeight.Enabled = false;
有什么建议么?先谢谢你了。如果您需要任何其他信息或澄清,请告诉我!
添加了组合框填充方法
try
{
List<PreviousVersionData> listID = PreviousVersionData.getDatabase();
if (listID != null)
{
foreach (PreviousVersionData l in listID)
{
cmboBoxPreviousVersion.Items.Add(string.Format("{0} - {1}", l.FormatID, l.FormatName));
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}