我目前有组合框在未选择单元格时显示 valuemember。单击单元格,显示成员显示以进行选择。在进行选择并单击 valuemember 后确实会更改为正确的数字,但我希望它在离开单元格后显示显示成员。
//class to hold the data
private class PriorityData
{
public string PriorityName { get; set; }
public string PriorityCode { get; set; }
public Color PriorityColor { get; set; }
}
//Construct the Priority column
_priorityColumn = new DataGridViewComboBoxColumn
{
ValueMember = "PriorityCode",
DisplayMember = "PriorityName",
Name = "Priority",
DataPropertyName = "Priority",
HeaderText = "Priority",
SortMode = DataGridViewColumnSortMode.NotSortable
};
private void LoadPriorityList()
{
try
{
using (var sqlConn = new SqlConnection(Program.sqlMgr.ConnectionString))
{
const string query = "SELECT * FROM mcPriority";
using (var da = new SqlDataAdapter(query, sqlConn))
{
var priorityTable = new DataTable();
priorityTable.Clear();
da.Fill(priorityTable);
//Clear the list
_priorityList.Clear();
//Add the list of shuttels from the database to the shuttle list for the shuttle combo box column
foreach (DataRow row in priorityTable.Rows)
{
_priorityList.Add(new PriorityData() { PriorityName = row["PriorityName"].ToString(), PriorityCode = row["PriorityCode"].ToString(), PriorityColor = Color.FromArgb(row["ColorCode"].ToInt()) });
}
//Bind the part combo box column to the shuttle list
_priorityColumn.DataSource = _priorityList;
}
}
}
catch (Exception ex)
{
MessageBox.Show($"Message: {ex.Message}{Environment.NewLine + Environment.NewLine} Class: {nameof(PaintQueueData)} Method: {nameof(LoadPriorityList)}");
}
}
我能够将数据很好地输入到gridview中,所有人都已经验证了一直到屏幕显示,displaymember的值确实是DisplayName。
从下拉列表中选择一个选项后,显示显示成员。
然后单击单元格外,它会恢复为值成员。
任何和所有的帮助将不胜感激,被困在这一段时间。