Ich denke nur, wenn es möglich ist, die Elemente in Listbox automatisch anzuzeigen, wenn Hauptformular neu geladen wird.Zeige Artikel in Listbox automatisch, wenn Main Form neu geladen wird
FrmMain frm = new FrmMain();
frm.ShowDialog();
Und wenn das Hauptformular angezeigt wird, werden die Elemente in Listbox automatisch ohne Klicks oder Keydown-Ereignisse angezeigt. Ist das möglich??
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();
Der obige Code ist für den Suchknopf.
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
}
}
}
}
Und das ist für die Update-Button
Wie füllen Sie das Listenfeld? Machen Sie es als eine Methode und rufen Sie form_Load –
Ich bevölkere es mit einer Schaltfläche namens Search item. Aber in First Run sollte die Listbox zuerst leer sein und dann, wenn ich den Button aktualisiere, wird das Mainform neu geladen und die Items in der Listbox angezeigt. – James
ok dann diesen Code in der Frage –