在 C# 中,我使用枚举并将它们作为字符串添加到列表中。我将列表与 datagridview 绑定。在 datagridview 事件中,我想单击单元格并执行操作。
我将如何使用枚举作为索引而不是行来做到这一点?
public enum QSystems { WindowsSystem, systemCheck, QDependencies }
_items = new List<string>();
_items.Add(QSystems.WindowsSystem.ToString());
_items.Add(QSystems.systemCheck.ToString());
_items.Add(QSystems.QDependencies.ToString());
在datagridview中
private void dataGridView2_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
{
_ckecklist = new List<FileStatus>();
switch (e.RowIndex) //this is wrong
{
case (short)QSystems.WindowsSystem:
_ckecklist.Clear();
ShowSystemStatus();
dataGridView1.DataSource = _ckecklist;
SetDatagriDview();
dataGridView1.Show();
break;
case (short)QSystems.systemCheck:
_ckecklist.Clear();
ShowNStatus();
dataGridView1.DataSource = _ckecklist;
SetDatagriDview();
dataGridView1.Show();
break;
case (short)QSystems.QDependencies:
_ckecklist.Clear();
ShowQDependencies();
dataGridView1.DataSource = _ckecklist;
SetDatagriDview();
dataGridView1.Show();
break;
}
}