gpt4 book ai didi

c# - 在 listView1_MouseClick 上显示特定项目

转载 作者:太空宇宙 更新时间:2023-11-03 13:37:50 24 4
gpt4 key购买 nike

在 Quize 方法中,我传递了 qestions,其中包含我要使用 DisplayQuestion() 显示的所有问题集,Question 是我的类,问题是我只显示第一个问题,如果假设 questions 包含 10 个问题,我如何在单击 listviewItem 时显示它们,而不是在我显示的 listviewItem 中数字(1 2 3 4 5 ....10),当我点击每个数字时,我如何显示点击时显示的特定问题,如果没有点击,所有问题如何使用计时器一一显示

public partial class GroupExmStart : Form
{
string[] randomQsn = new string[totQsn + 1]; //totQsn is the total number of question for e.g.10
public GroupExmStart(string GroupName, string DurationID)
{
InitializeComponent();
this.GrpID=GroupName;
TopiID=db.GetTopicIDForGroup(GrpID);

string[] conf = db.GetConfiguration(Convert.ToInt16(DurationID)).Split('|');

Question qsn = new Question();
var questions = qsn.Foo(TopiID, conf);
int z = Quiz(questions);

totQsn = Convert.ToInt16(conf[0]);
for (int kk = 1; kk <= totQsn; kk++)
{
ListViewItem lvi = new ListViewItem();
lvi.Text = kk.ToString();
listView1.Items.Add(lvi);
}
randomQsn = new string[totQsn + 1];
timer1.Interval = 1000; //1000ms = 1sec
timer1.Tick += new EventHandler(timer1_Tick);
timer1.Start();
}
int Quiz(List<Question> questions)
{
foreach (Question question in questions)
{
DisplayQuestion(question);
}
return 0;
}
private void DisplayQuestion(Question question)
{
string Q = question.Text;
label5.Text = Q;
string OP1 = question.Option1;
string OP2 = question.Option2;
string OP3 = question.Option3;
string OP4 = question.Option4;
radioButton12.Text = OP1;
radioButton11.Text = OP2;
radioButton10.Text = OP3;
radioButton9.Text = OP4;
}
private void listView1_MouseClick(object sender, MouseEventArgs e)
{
if (randomQsn.GetLength(0) >= 0)
{
if (listView1.SelectedItems.Count > 0)
{
//here how should i get That particular Question so that i can display it
//something like this ? //Convert.ToInt16(listView1.SelectedItems[0].SubItems[0].Text)
DisplayQuestion(question);
}
}
}
private void timer1_Tick(object sender, EventArgs e)
{
tik++;
if (tik == 60)
{
label1.Text = (Convert.ToInt16(label1.Text) - 1).ToString();
tik = 0;
}
}
}

提前感谢您的帮助

最佳答案

以下是您要查找的内容。您必须获取 ListView 项的文本并将其用作问题的索引。

if (listView1.SelectedItems.Count > 0)
{
var q = Convert.ToInt16(listView1.SelectedItems[0].Text);
var selectedQuestion = questions[q - 1];
DisplayQuestion(selectedQuestion);
}

为了使其工作,请将构造函数修改为以下内容:

private List<Question> questions;
public partial class GroupExmStart : Form
{
string[] randomQsn = new string[totQsn + 1]; //totQsn is the total number of question for e.g.10
public GroupExmStart(string GroupName, string DurationID)
{
InitializeComponent();
this.GrpID=GroupName;
TopiID=db.GetTopicIDForGroup(GrpID);

string[] conf = db.GetConfiguration(Convert.ToInt16(DurationID)).Split('|');

Question qsn = new Question();

/// THIS IS MODIFIED //
questions = qsn.Foo(TopiID, conf);
int z = Quiz(questions);

totQsn = Convert.ToInt16(conf[0]);
for (int kk = 1; kk <= totQsn; kk++)
{
ListViewItem lvi = new ListViewItem();
lvi.Text = kk.ToString();
listView1.Items.Add(lvi);
}
randomQsn = new string[totQsn + 1];
timer1.Interval = 1000; //1000ms = 1sec
timer1.Tick += new EventHandler(timer1_Tick);
timer1.Start();
}

关于c# - 在 listView1_MouseClick 上显示特定项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18124050/

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