I have the following code on form load that works correctly to create an array of buttons to filter a database by last name for A-Z and #'s and disable any buttons that have no results return for that letter:
private void getAlpha()
{
int locX = 12,
locY = 76,
i = 0;
string sqlText = "";
char[] delimiterChars = { ',' };
string alphabet = "A,B,C,D,E,F,G,H,I,J,K,L,M,#,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,All";
string[] words = alphabet.Split(delimiterChars);
foreach (string s in words)
{
button = new Button();
button.Name = s + "_button";
string buttonName = s;
button.Size = new Size(30, 30);
button.Location = new Point(locX, locY);
button.Text = s.ToString();
button.Font = new Font(button.Font, FontStyle.Bold);
this.Controls.Add(button);
button.Refresh();
i = i + 1;
button.Click += new EventHandler(button_click);
locY += 30;
if (i == 14)
{
locY = 76;
locX = 42;
}
m_dtContacts.Clear();
if (s == "#")
{
sqlText = "SELECT * FROM Contacts WHERE [LastName] LIKE '[0-9]%'";
}
else if (s == "All")
{
sqlText = "Select * From Contacts order by [LastName],[FirstName]";
}
else
{
sqlText = "Select * From Contacts where [LastName] like '" + buttonName + "%" + "'";
}
m_daDataAdapter =
new OleDbDataAdapter(sqlText, m_cnADONetConnection);
OleDbCommandBuilder m_cbCommandBuilder =
new OleDbCommandBuilder(m_daDataAdapter);
m_daDataAdapter.Fill(m_dtContacts);
if (m_dtContacts.Rows.Count == 0)
{
button.Enabled = false;
}
else
{
button.Enabled = true;
}
}
}
On form load it works as expected but calling it from an update, add, delete function does nothing. It should disable or enable a button based on adding or delete the only record with that letter. I have tried modifying it for these from the form load code but so far nothing.
Any ideas or suggestions would be appreciated.
private void getAlpha()
{
int locX = 12,
locY = 76,
i = 0;
string sqlText = "";
char[] delimiterChars = { ',' };
string alphabet = "A,B,C,D,E,F,G,H,I,J,K,L,M,#,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,All";
string[] words = alphabet.Split(delimiterChars);
foreach (string s in words)
{
button = new Button();
button.Name = s + "_button";
string buttonName = s;
button.Size = new Size(30, 30);
button.Location = new Point(locX, locY);
button.Text = s.ToString();
button.Font = new Font(button.Font, FontStyle.Bold);
this.Controls.Add(button);
button.Refresh();
i = i + 1;
button.Click += new EventHandler(button_click);
locY += 30;
if (i == 14)
{
locY = 76;
locX = 42;
}
m_dtContacts.Clear();
if (s == "#")
{
sqlText = "SELECT * FROM Contacts WHERE [LastName] LIKE '[0-9]%'";
}
else if (s == "All")
{
sqlText = "Select * From Contacts order by [LastName],[FirstName]";
}
else
{
sqlText = "Select * From Contacts where [LastName] like '" + buttonName + "%" + "'";
}
m_daDataAdapter =
new OleDbDataAdapter(sqlText, m_cnADONetConnection);
OleDbCommandBuilder m_cbCommandBuilder =
new OleDbCommandBuilder(m_daDataAdapter);
m_daDataAdapter.Fill(m_dtContacts);
if (m_dtContacts.Rows.Count == 0)
{
button.Enabled = false;
}
else
{
button.Enabled = true;
}
}
}
On form load it works as expected but calling it from an update, add, delete function does nothing. It should disable or enable a button based on adding or delete the only record with that letter. I have tried modifying it for these from the form load code but so far nothing.
Any ideas or suggestions would be appreciated.