Ublic static void SetComboList (DevExpress. xtraEditors. comboBoxEdit ComboList, string QuerySQL, ArrayList arrSource = null, DataTable dtSource = null, string FirstRowText = "", bool bSelectFirstItem = false, bool bEditable = false)
{
DataTable dtList = null;
If (dtSource! = Null)
{
DtList = dtSource;
}
Else if (arrSource! = Null)
{
DtList = new DataTable ();
DtList. Columns. Add ("name ");
Foreach (string s in arrSource)
{
DtList. Rows. Add (s );
}
}
Else if (! String. IsNullOrEmpty (QuerySQL ))
{
Try
{
DtList = SqlHelper. ExecuteDataTable (SqlHelper. ConnString, CommandType. Text, QuerySQL, null );
}
Catch (Exception ex)
{
Common. DisplayMsg ("Data Access exception:", ex. Message. ToString ());
Return;
}
}
Else {return ;}
Int intCount = (dtList! = Null )? DtList. Rows. Count: 0;
If (bEditable)
{
ComboList. Properties. TextEditStyle = TextEditStyles. Standard;
}
Else
{
ComboList. Properties. TextEditStyle = TextEditStyles. DisableTextEditor; // You Cannot edit the comboBox text value.
}
ComboList. Properties. Items. Clear ();
If (! String. IsNullOrEmpty (FirstRowText) ComboList. Properties. Items. Add (FirstRowText );
If (intCount> 0)
{
For (int I = 0; I <intCount; I ++)
{
ComboList. Properties. Items. Add (dtList. Rows [I] [0]. ToString ());
}
}
If (bSelectFirstItem) ComboList. SelectedIndex = 0; // you can specify 1st items.
}
From: keenweiwei's column