Пример #1
0
        private void populaComboCentroCustos()
        {
            // Bind combobox to dictionary
            Dictionary <string, string> vlrs = new Dictionary <string, string>();

            vlrs.Add("", "");

            System.Data.DataTable dt = Colaboradores.GetCentroCustos();
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                vlrs.Add(dt.Rows[i].ItemArray[0].ToString(), dt.Rows[i].ItemArray[0].ToString());
            }

            cmbCentroCusto.DataSource    = new BindingSource(vlrs, null);
            cmbCentroCusto.DisplayMember = "Value";
            cmbCentroCusto.ValueMember   = "Key";

            // Get combobox selection (in handler)
            string value = ((KeyValuePair <string, string>)cmbCentroCusto.SelectedItem).Value;
        }