I've been working for this an hour but still I don't know what is the reason why it's not refreshing the listview after hitting the "NO" button in dialog box.
I have frmCompanyList (main form) and located here the listview next I have frmCompanyEntry (childform).
I already tried using this Refresh() and it's not working. But if I click the button "Refresh" in my frmCompanyList its working.
So here's my code:
frmCompanyEntry:
DialogResult dialogResult = MessageBox.Show(Global._strInsertAgainMsg + "company?", Global._strTitleMsg, MessageBoxButtons.YesNo);
if (dialogResult == DialogResult.Yes)
{
clearAll();
}
else if (dialogResult == DialogResult.No)
{
this.Close();
clearAll();
frmCompanyList _company = new frmCompanyList();
_company.PerformRefresh();
}
Then here's the frmCompanyList:
public void PerformRefresh()
{
__toolCmbStatus.SelectedIndex = 1;
loadCompany(__toolTxtSearch.Text);
}
public void loadCompany(string _strSearch)
{
try
{
ListViewItem Item;
__lvwCompany.Items.Clear();
string _strWhereStatement = "(fldCode LIKE '" + "%" + _strSearch + "%" + "' OR fldCompany LIKE '" + "%" + _strSearch + "%" + "' OR fldAddress LIKE '" + "%" + _strSearch + "%" + "' OR fldContactNo LIKE '" + "%" + _strSearch + "%" + "' OR fldContactPerson LIKE '" + "%" + _strSearch + "%" + "')";
if (__toolCmbStatus.SelectedIndex.ToString() != "2")
{ _strQry = "SELECT * FROM tblCompany WHERE " + _strWhereStatement + " AND fldActive = '" + __toolCmbStatus.SelectedIndex.ToString() + "' ORDER BY fldCompany ASC"; }
else
{ _strQry = "SELECT * FROM tblCompany WHERE " + _strWhereStatement + " ORDER BY fldCompany ASC"; }
using (SQLConnect.SqlCommandEx _SQLCMD = new SQLConnect.SqlCommandEx(_strQry))
{
DataTable dt = _SQLCMD.GetDataTable();
__lblTotalRecord.Text = dt.Rows.Count.ToString();
if (dt.Rows.Count == 0)
{
Item = new ListViewItem("");
Item.SubItems.Add(Global._strEmptyMsg);
Item.SubItems[0].ForeColor = System.Drawing.Color.Red;
__lvwCompany.Items.Add(Item);
}
else
{
foreach (DataRow DR in dt.Rows)
{
Item = new ListViewItem(DR[0].ToString());
Item.SubItems.Add(DR[2].ToString());
Item.SubItems.Add(DR[3].ToString());
Item.SubItems.Add(DR[4].ToString());
Item.SubItems.Add(DR[5].ToString());
Item.SubItems.Add(DR[1].ToString());
if (DR[6].ToString() == "False")
{
Item.SubItems.Add("Inactive");
Item.SubItems[6].ForeColor = System.Drawing.Color.Red;
for (int x = 0; x <= 6; x++)
{
Item.SubItems[x].Font = new Font(__lvwCompany.Font, FontStyle.Italic);
}
Item.UseItemStyleForSubItems = false;
}
else
{
Item.SubItems.Add("Active");
Item.SubItems[6].ForeColor = System.Drawing.Color.Green;
Item.UseItemStyleForSubItems = false;
}
__lvwCompany.Items.Add(Item);
}
}
}
}
catch (Exception ex) { MessageBox.Show("Please contact your administrator. Error: " + ex, Global._strTitleMsg); }
}