1

わかりました、最後の試行:)ユーザーが入力する必要がある小さなフォーム(名前、日付など)があります。ユーザーが「送信」をクリックすると、彼の名前と日付が必要です(ユーザーはDateTimePicker形式で日付を入力します) CheckedListBox に 1 つのアイテムとして表示されます (example="gil 17/12/2011") 可能ですか?

4

2 に答える 2

2

できますよ。ここでの秘訣は、ListBox(およびCheckedListBox)にのリストが含まれていることを知ることですObjectToStringそれらのオブジェクトのメソッドを使用して表示します。ToStringあなたがしなければならないのは、オーバーライドを持つあなた自身のタイプをリストに入力することです。

using System;
using System.Drawing;
using System.Windows.Forms;

public class Form1 : Form
{
    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new Form1());
    }

    public Form1()
    {
        Controls.Add(new Label { Text = "Name", Location = new Point(10, 10), AutoSize = true });
        Controls.Add(new TextBox { Name = "Name", Location = new Point(60, 10) });
        Controls.Add(new Label { Text = "Date", Location = new Point(10, 40), AutoSize = true });
        Controls.Add(new DateTimePicker { Name = "Date", Location = new Point(60, 40) });
        Controls.Add(new Button { Name = "Submit", Text = "Submit", Location = new Point(10, 70) });
        Controls.Add(new CheckedListBox { Name = "List", Location = new Point(10, 100), Size = new Size(ClientSize.Width - 20, ClientSize.Height - 100 - 10) });
        Controls["Submit"].Click += (s, e) =>
                (Controls["List"] as CheckedListBox).Items.Add(new MyItem { Name = Controls["Name"].Text, Date = (Controls["Date"] as DateTimePicker).Value });
    }
}

public class MyItem
{
    public string Name { get; set; }
    public DateTime Date { get; set; }

    public override string ToString()
    {
        return String.Format("{0} {1}", Name, Date);
    }
}
于 2011-04-17T19:49:49.243 に答える
0

なんらかの努力がなければ、いいえ、それはできませんが、それは自分で実装できます。Editable ListViewとListView subitemsのインプレース編集をご覧ください。

于 2011-04-17T19:26:39.753 に答える