こんにちは、リストボックスのアイテムを取得する方法と、すべてのチェックリストボックスをクリックして数字を追加してテキストボックスに表示したいときに、まだ混乱しています。たとえば、テキストボックスに表示される 300 を含むチェックリストボックスのインデックス 1 をチェックします。次に、checkboxlist のインデックス 2 に 100 が含まれていることも確認し、400 を表示します。次に、checkboxlist のインデックス 3 に 200 が含まれていることを確認すると、チェックボックスに 600 が表示されます。
私のコード:
namespace ggg
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
listBox1.Items.Clear();
listBox2.Items.Clear();
textBox1.Clear();
foreach (string s in checkedListBox1.CheckedItems)
listBox1.Items.Add(s);
foreach (int i in checkedListBox1.CheckedIndices)
{
if (i == 0)
{
listBox2.Items.Add(300);
decimal total = 300;
textBox1.Text += total;
}
if (i == 1)
{
listBox2.Items.Add(100);
decimal total = 100;
textBox1.Text += total;
}
if (i == 2)
{
listBox2.Items.Add(200);
decimal total = 200;
textBox1.Text += total;
}
}
}
}
}