Dynamic Fill ComboBox Winform example

public void FillCmb(ComboBox cmb, string query, string strValue, string strText, string strHeader)
    con = new SqlConnection(connectionString);            
    adp = new SqlDataAdapter(query, con);
    DataTable tbl = new DataTable();
    DataRow header = tbl.NewRow();
    if (!string.IsNullOrEmpty(strValue))
        header[strValue] = DBNull.Value;
    header[strText] =
        (string.IsNullOrEmpty(strHeader)) ? "Choose" : strHeader;
    tbl.Rows.InsertAt(header, 0);  
    cmb.DataSource = tbl;            
    cmb.DisplayMember = strText;            
    cmb.ValueMember = strValue;        
}//end fill cmb

string text = ((DataRowView)cbxSources.SelectedItem).Row[0].ToString();


Popular posts from this blog

c# Service Play Sound with NAudio example by Moshe

SOLVED The item could not be indexed successfully because the item failed in the indexing subsystem

JS/JQ simulate Enter event