Initiated from BB Quick Access Button
dataGridViewBC.ReadOnly = false;
dataGridViewBC.Columns[1].Visible = false;
this.toolStripStatusLabel1.Text = "";
this.textBoxSecurity.Text = "";
string BBSymbol = ((Button)sender).Text;
BBSymbol = (BBSymbol.Length == 1) ? BBSymbol.PadRight(2, ' ') : BBSymbol;
using (SqlConnection cn = new SqlConnection(connString))
{
cn.Open();
SqlCommand cmd = new SqlCommand(@"
select distinct
substring(ext_sec_id,1,len(ext_sec_id)-2),
substring(ticker,1,len(ticker)-2),
sec_name from csm_security where sec_typ_cd='Fut' and ticker like '" + BBSymbol + "__'", cn);
SqlDataReader r = cmd.ExecuteReader();
AutoCompleteStringCollection col = new AutoCompleteStringCollection();
string s = "";
while (r.Read())
{
s = " " + r.GetValue(0).ToString() + " " + r.GetValue(1).ToString() + " " + r.GetValue(2).ToString();
col.Add(s);
}
this.textBoxSecurity.AutoCompleteCustomSource = col;
this.textBoxSecurity.Focus();
if (col.Count == 1)
{
this.textBoxSecurity.Text = s;
FillGridView();
SetSelectedValueForAllComboEdit();
}
if (col.Count >= 2) SendKeys.Send(" ");
Initiated from Search Button
private void btnSearch_Click(object sender, EventArgs e)
{
dataGridViewBC.ReadOnly = false;
dataGridViewBC.Columns[1].Visible = false;
this.toolStripStatusLabel1.Text = "";
if (this.textBoxSecurity.Text.Length <= 1) return;
if (this.btnSearch.Text == "Get Rates" && this.textBoxSecurity.Text.Trim() != "No Match")
{
FillGridView();
SetSelectedValueForAllComboEdit();
}
if (this.btnSearch.Text == "Search")
{
Listlist = FindMatch(_SecurityList, this.textBoxSecurity.Text.Trim());
_MatchedCollection = new AutoCompleteStringCollection();
foreach (string s in list)
{
_MatchedCollection.Add(s);
}
if (_MatchedCollection.Count == 0) _MatchedCollection.Add(" No Match");
this.textBoxSecurity.AutoCompleteCustomSource = _MatchedCollection;
this.textBoxSecurity.Focus();
this.textBoxSecurity.Clear();
SendKeys.Send(" ");
this.btnSearch.Text = "Get Rates";
}
Friday, September 2, 2011
WinForm Google Suggest AutoComplete
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment