メインフォームがリロードされたときに自動的にリストボックス内の項目を表示できるかどうかを考えています。メインフォームがリロードされたときリストボックスに項目を自動的に表示
FrmMain frm = new FrmMain();
frm.ShowDialog();
メインフォームが表示されると、リストボックス内のアイテムは、クリックやキーダウンイベントなしで自動的に表示されます。これは可能ですか?
private void BtnSearch_Click(object sender, EventArgs e)
{
if (ACICTest.FindbyACICNo(textBox1.Text).Count() == 0)
{
MessageBox.Show("No record found in the database!","ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
listBox1.DataSource = ACICTest.FindbyACICNo(textBox1.Text).ToList();
listBox1.DisplayMember = "ACICNo";
listBox1.ValueMember = "ACICId";
listBox1.Focus();
}
dataGridView1.Columns.Clear();
上記のコードは検索ボタン用です。
private void BtnUpdate_Click(object sender, EventArgs e)
{
int breaker = 0;
if (MessageBox.Show("Are you sure want to update the data?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
{
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
if (Convert.ToInt16(dataGridView1.Rows[i].Cells["Prior Year"].Value) > 1)
{
MessageBox.Show("Accept 1 or 0 only. [Prior Year = 1] [Non-Prior = 0]", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
breaker += 1;
break;
}
else
{
ACICComplete.UpdateData(new ACICCombinedDetails
{
GFCheckID = Convert.ToInt32(dataGridView1.Rows[i].Cells["ID"].Value),
PYear = Convert.ToInt16(dataGridView1.Rows[i].Cells["Prior Year"].Value)
});
}
}
if (breaker >= 1)
{
//Empty Code
}
else
{
if (MessageBox.Show("Data successfully updated!", "Successful", MessageBoxButtons.OK, MessageBoxIcon.Information) == System.Windows.Forms.DialogResult.OK)
{
BtnAdd.Enabled = false;
BtnSave.Enabled = false;
BtnCancel.Enabled = false;
BtnUpdate.Enabled = false;
listBox1.Enabled = true;
BtnTrustAdd.Enabled = false;
BtnTrustRemove.Enabled = false;
BtnEdit.Enabled = false;
dataGridView1.Columns["Prior Year"].DefaultCellStyle.BackColor = Color.White;
FrmMain.ActiveForm.Dispose();
FrmMain frm = new FrmMain();
frm.ShowDialog();
//In this portion the Main form shows up but I want listbox also show the items
}
}
}
}
そして、これは、更新ボタン
を?それをメソッドとして作成し、form_Loadを呼び出す –
Search itemという名前のボタンを使用して入力します。しかし、最初の実行リストボックスで最初に空にする必要がありますし、私はボタンの更新を押すとmainformをリロードし、リストボックスに項目を表示します。 – James
質問にそのコードを含めてください。 –