gpt4 book ai didi

c# - 引用列按顺序排列

转载 作者:行者123 更新时间:2023-11-29 08:27:21 24 4
gpt4 key购买 nike

我有一个 MySQL 数据库表(我正在使用 Entity Framework ),如下所示: enter image description here

以下是我用来在 WPF 上检索和填充它们的代码: CRUD 类文件:

        //Get all records based on ActivityID and TaskID.
public IList<Model.questionhint> GetRecords(int listTask, int listActivity)
{
IList<Model.questionhint> lstRecords = context.questionhints.ToList();
return lstRecords.Where(a => a.TaskID == listTask && a.ActivityID == listActivity).ToList();

}

隐藏代码:

      public MainWindow2()
{
InitializeComponent();
PopulateQuestion(1, 5);
}

private void PopulateQuestion(int activityID, int taskID)
{
IList<Model.questionhint> lstQuestionHints = qh.GetRecords(taskID, activityID);

foreach(Model.questionhint qhm in lstQuestionHints)
{

TextBlock tb = new TextBlock();
tb.Text = qhm.QuestionContent;
tb.FontWeight = FontWeights.Bold;
tb.FontSize = 24;
WrapPanelTest.Children.Add(lbl);

if (qhm.Option1.Trim().Length > 0 &&
qhm.Option2.Trim().Length > 0)
{
ComboBox cb = new ComboBox();
cb.Items.Add(qhm.Option1);
cb.Items.Add(qhm.Option2);
cb.Width = 200;
WrapPanelTest.Children.Add(cb);
}

}
}

它如何出现在我的程序中:

enter image description here

正如你所看到的,这些问题都是复合在一起的,我想根据上面数据库表中的 QuestionNo 将它们分开(例如,具有相同 QuestionNo 的几条记录应该复合在一起。)但我完全不知道如何 。我想将它们分开:

I [comboBox] to have a nap every afternoon.

The sun [comboBox] not move round the earth.

感谢对此的任何帮助,提前致谢。

最佳答案

试试这个

     StackPanel sp=new StackPanel();
foreach(Model.questionhint qhm in lstQuestionHints)
{
StackPanel sp1=new StackPanel(){Orientation=Orientation.Horizontal};
TextBlock tb = new TextBlock();
tb.Text = qhm.QuestionContent;
tb.FontWeight = FontWeights.Bold;
tb.FontSize = 24;
sp1.Children.Add(lbl);

if (qhm.Option1.Trim().Length > 0 &&
qhm.Option2.Trim().Length > 0)
{
ComboBox cb = new ComboBox();
cb.Items.Add(qhm.Option1);
cb.Items.Add(qhm.Option2);
cb.Width = 200;
sp1.Children.Add(cb);
}
sp.Children.Add(sp1);
}
WrapPanelTest.Children.Add(sp);

关于c# - 引用列按顺序排列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17584451/

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