C# 在ListView上显示特定项目1\u鼠标单击
在提问方法中,我传递的是C# 在ListView上显示特定项目1\u鼠标单击,c#,.net,C#,.net,在提问方法中,我传递的是qestions,其中包含我所有的问题集,这些问题将使用DisplayQuestion()显示,Question是我的类,问题是我只显示第一个问题,如果假设问题包含10个问题,而不是在listviewItem中我显示了数字(1 2 3 4 5…10),当我单击listviewItem时,如何显示这些问题,当我单击每个数字时,我如何显示单击时显示的特定问题,如果未单击,如何使用计时器逐个显示所有问题 public partial class GroupExmStart :
qestions
,其中包含我所有的问题集,这些问题将使用DisplayQuestion()
显示,Question
是我的类,问题是我只显示第一个问题,如果假设问题
包含10个问题,而不是在listviewItem中我显示了数字(1 2 3 4 5…10),当我单击listviewItem时,如何显示这些问题,当我单击每个数字时,我如何显示单击时显示的特定问题,如果未单击,如何使用计时器逐个显示所有问题
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;
}
}
}
public分部类GroupExmStart:Form
{
string[]randomQsn=新字符串[totQsn+1];//totQsn是例如10的问题总数
公共GroupExmStart(字符串GroupName、字符串DurationID)
{
初始化组件();
this.GrpID=GroupName;
TopiID=db.GetTopicIDForGroup(GrpID);
字符串[]conf=db.GetConfiguration(Convert.ToInt16(DurationID)).Split(“|”);
问题qsn=新问题();
变量问题=qsn.Foo(TopiID,conf);
int z=测验(问题);
totQsn=Convert.ToInt16(conf[0]);
对于(int kk=1;kk=0)
{
如果(listView1.SelectedItems.Count>0)
{
//在这里,我应该如何得到这个特定的问题,以便我可以显示它
//类似于以下内容?//Convert.ToInt16(listView1.SelectedItems[0]。子项[0]。文本)
问题(问题),;
}
}
}
私有无效计时器1_刻度(对象发送方,事件参数e)
{
tik++;
如果(tik==60)
{
label1.Text=(Convert.ToInt16(label1.Text)-1.ToString();
tik=0;
}
}
}
提前感谢您的帮助以下是您需要的。您必须获取列表视图项的文本,并将其用作问题的索引
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();
}
私人列表问题;
公共分部类GroupExmStart:表单
{
string[]randomQsn=新字符串[totQsn+1];//totQsn是例如10的问题总数
公共GroupExmStart(字符串GroupName、字符串DurationID)
{
初始化组件();
this.GrpID=GroupName;
TopiID=db.GetTopicIDForGroup(GrpID);
字符串[]conf=db.GetConfiguration(Convert.ToInt16(DurationID)).Split(“|”);
问题qsn=新问题();
///这是修改过的//
问题=qsn.Foo(TopiID,conf);
int z=测验(问题);
totQsn=Convert.ToInt16(conf[0]);
对于(int kk=1;kk),我尝试过这样做Question Question=randomQsn[Convert.ToInt16(listView1.SelectedItems[0].SubItems[0].Text)-1];
但是在这里获取对象引用null
异常,无法获取解决问题缺少很多相关代码,包括与问题无关的代码。