Esempio n. 1
0
 private void btn1_Click(object sender, EventArgs e)
 {
     try
     {
         DataTable dt = _DictManageModel.GetDictInfo();
         dataGridView1.DataSource = dt;
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
        /// <summary>
        /// 加载字典名称
        /// </summary>
        private void LoadDictItemName()
        {
            try
            {
                DataTable dDictionary = _dbDicModel.GetDictInfo();
                //需要将数据源设置为null,否则刷新时会提示:设置 DataSource 属性后无法修改项集合 错误。
                cbxDictionary.DataSource = null;
                cbxDictionary.Items.Clear();

                cbxDictionary.DisplayMember = "字典名称";
                cbxDictionary.ValueMember   = "字典名称";

                cbxDictionary.DataSource = dDictionary;

                if (cbxDictionary.Items.Count > 0)
                {
                    cbxDictionary.SelectedIndex = 0;
                }
            }
            catch (Exception ex)
            {
                MsgBox.ShowException(ex, this);
            }
        }