1

私のシナリオ:

私は、GUIからクラスを追加し、そのクラスをセクションにリンクする必要があるWindowsフォームアプリケーションで学校管理システムを実行しています(どのクラスにどのセクションがあるかが表示されます)。そのために、セクションからセクションをロードして、それらを表示したいチェックボックスで、ユーザーが追加するクラスのセクションを選択できるようにします。

問題 :

新しいクラスのセクションを簡単に選択できるチェックボックスにセクションを表示できません

私が欲しいもの:

読み込んでいるセクションをチェック ボックスの形式で表示する必要があります。

私のコード:

try
{
    Sections objSections = new Sections();
    objSections.LoadAll();
    if (objSections.RowCount > 0)
    {

        List<CheckBox> Sectionlist=new List<CheckBox>();
        for (int i = 0; i < objSections.RowCount; i++)
        {

            Sectionlist.Add(objSections.Name);  // here is error "Some invalid arguments"
        }
    }
    else
    {
        DevComponents.DotNetBar.MessageBoxEx.Show(" No Section Found, Please Add some Section And linke them with Classes. ", " Information Message! ");
        return;
    }
}
catch (Exception ee)
{
    DevComponents.DotNetBar.MessageBoxEx.Show(ee.Message);
    return;
}
4

2 に答える 2

0

問題は、 を持っていて、このリストList<CheckBox>に を追加しようとしていることにあると思います。string

おそらくリストリストが必要です。

list.Add(objSections.Name); // which will be a valid argument assuming `.Name` is of type string.

追加の注意として、あなたは for ループにいるので、毎回新しい List インスタンスを作成する必要はありません。

List<string> list = new List<string>();

 for (int i =0; i< objSections.RowCount; i++) {
     list.Add(objSections.Name); // I still assume this line will add the same entry for each iteration, you need to access the correct index of the array
 }
于 2013-09-09T09:40:10.113 に答える