gpt4 book ai didi

c# - datagridview 事件的枚举索引

转载 作者:行者123 更新时间:2023-11-30 17:56:41 24 4
gpt4 key购买 nike

在 C# 中,我使用枚举并将它们作为字符串添加到列表中。我将列表与 datagridview 绑定(bind)。在 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());

在数据 GridView 中

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;
}
}

最佳答案

您可以获取选择的字符串并使用解析将其转换为枚举值,示例:

Colors colorValue = (Colors) Enum.Parse(typeof(Colors), colorString);        

另一个例子:

String WhatDayItIs = DayOfWeek.Monday.ToString();     

DayOfWeek WhatDayItIsDOW;

if (Enum.IsDefined(typeof(DayOfWeek), WhatDayItIs))
WhatDayItIsDOW = (DayOfWeek)Enum.Parse(typeof(DayOfWeek), WhatDayItIs);

关于c# - datagridview 事件的枚举索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13953152/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com