/// <summary> /// 입력코드값으로 콤보박스의 리스트를 선택합니다. /// </summary> /// <param name="combo">ComboBox</param> public static void SetComboValue(System.Windows.Forms.ComboBox combo) { try { if (combo.Text != "") { if (Char.IsNumber(combo.Text, 0)) { combo.SelectedIndex = combo.FindString(combo.Text, -1); } else { DataTable dt = (DataTable)combo.DataSource; DataRow[] row = dt.Select("TEXT LIKE '%" + combo.Text + "%'"); if (row != null) { if (row.Length > 0) { combo.SelectedIndex = combo.FindString(row[0]["VAL"].ToString(), -1); } } dt = null; row = null; } } } catch (Exception ex) { throw ex; } }
//public DataTable LoadData(string querytype) //{ // connects.connect.Close(); // DataTable db; // using (var ds = new DataSet()) // { // connects.connect.Open(); // using (SqlDataAdapter da = new SqlDataAdapter(querytype, connects.ConnectionString())) // { // da.Fill(ds, "table"); // } // db = ds.Tables[0]; // return db; // } //} //public string GetFildNo(string query) //{ // double FieldNo; // double lngfiled; // double lngcount; // string strZero; // try // { // //connectionString.connect.Close(); // connects.connect.Close(); // command = new SqlCommand(query, connects.connect); // adp = new SqlDataAdapter(command); // connects.connect.Open(); // reader = command.ExecuteReader(); // if (reader.Read()) // { // retVal = Convert.ToString(reader.GetValue(0)); // FieldNo = Convert.ToInt32(retVal.ToString()) + 1; // if (retVal.Length <= 3) // { // lngcount = 3 - retVal.Length; // if (lngcount == 2) // { // strZero = "00"; // } // else if (lngcount == 1) // { // strZero = "0"; // } // } // //retVal = String.Format("{0}{1}", strZero, FieldNo); // } // //else // //{ // // retVal = "-1"; // //} // } // catch (Exception ex) // { // retVal = String.Format("{0}---{1}----ExecuteCommand_withValue", ex.Message, ex.StackTrace); // } // finally // { // connects.connect.Close(); // } // return retVal; //} //public DataTable LoadData(string querytype, string TblName) //{ // connects.connect.Close(); // DataTable db = new DataTable(TblName); // using (var ds = new DataSet()) // { // connects.connect.Open(); // using (SqlDataAdapter da = new SqlDataAdapter(querytype, connects.ConnectionString())) // { // da.Fill(ds, TblName); // } // db = ds.Tables[0]; // return db; // } //} public static void AutoComplete(System.Windows.Forms.ComboBox cb, System.Windows.Forms.KeyPressEventArgs e, bool blnLimitToList) { string strFindStr = ""; if (e.KeyChar == (char)8) { if (cb.SelectionStart <= 1) { cb.Text = ""; return; } if (cb.SelectionLength == 0) { strFindStr = cb.Text.Substring(0, cb.Text.Length - 1); } else { strFindStr = cb.Text.Substring(0, cb.SelectionStart - 1); } } else { if (cb.SelectionLength == 0) { strFindStr = cb.Text + e.KeyChar; } else { strFindStr = cb.Text.Substring(0, cb.SelectionStart) + e.KeyChar; } } int intIdx = -1; // Search the string in the ComboBox list. intIdx = cb.FindString(strFindStr); if (intIdx != -1) { cb.SelectedText = ""; cb.SelectedIndex = intIdx; cb.SelectionStart = strFindStr.Length; cb.SelectionLength = cb.Text.Length; e.Handled = true; } else { e.Handled = blnLimitToList; } }
public static void SetComboboxSelectedByValue(System.Windows.Forms.ComboBox cbx, object value) { cbx.SelectedIndex = cbx.FindString(value.ToString()); }