[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details

Sorting Databound Combobox C#

Asked by ProWebNetworks in C# Programming Language

Hi Guys,

I need to allow the user to click a button to sort a combo box based on fields that are not showing in the combo box.

Here is my code below...

Any suggestions?

DisplayValue is a Concatenation of CustomerNumber + ' - ' + CustomerName

The stored procedure has 3 fields: CustomerNumber, CustomerName, & DisplayValue
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
public partial class frmConfigurePriceID : Form
    {
        string CustomerSort = "CustomerName ASC"; 

        public frmConfigurePriceID()
        {
            InitializeComponent();
        } 
        private void frmConfigurePriceID_Load(object sender, EventArgs e)
        {
            Load_cboCustomer();
        }
    
    private void Load_cboCustomer()
    {
            cboCustomer.Items.Clear(); 
            try
            {
            SqlConnection cbocn = new SqlConnection(PubVar.dbConn);
            cbocn.Open(); 
            SqlCommand cbocmd = new SqlCommand(PubVar.dbConn, cbocn);
            cbocmd.CommandText = "sp_CustomerNamesNumbers";
            cbocmd.CommandType = CommandType.StoredProcedure; 
            SqlParameter param;
            param = cbocmd.Parameters.AddWithValue("@CompanyID", PubVar.CompanyID); 
            DataTable cbotbl = new DataTable();
          
            
            cboCustomer.DisplayMember = "DisplayValue";
            cboCustomer.ValueMember = "Cust5Digit"; 
            
                 
         
                SqlDataReader rdr1 = cbocmd.ExecuteReader();
                
                
                BindingSource bs1 = new BindingSource(rdr1, null); 
                
               
                cboCustomer.DataSource = bs1; 

                rdr1.Close(); 
            } 
            catch (Exception excep)
            {
                MessageBox.Show(excep.Message + "- Source: Load_cboCustomers()");
            }
    
    } 

    
    
    
    }
}
[+][-]11/04/09 04:43 PM, ID: 25745785Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/04/09 11:24 PM, ID: 25747363Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-92 - Hierarchy / EE_QW_3_20080625