Пример #1
0
        public void LoadData()
        {
            if (String.IsNullOrWhiteSpace(DataSet))
            {
                return;
            }

            if (DS == null)
            {
                throw new Exception(String.Format("Object name: {0} \rNo dataset found named: {1}", this.Name, DataSet));
            }

            if (DS.Connection != null && !String.IsNullOrWhiteSpace(DS.CommandText) && this.Items.Count == 0)
            {
                if (!DS.Active)
                {
                    DS.Open();
                }

                if (!String.IsNullOrWhiteSpace(Key) && !String.IsNullOrWhiteSpace(DisplayText))
                {
                    if (!DS.DataTable.Columns.Contains(Key))
                    {
                        throw new Exception(String.Format("Object name: {0} \rNo Key column found named: {1}", this.Name, Key));
                    }
                    if (!DS.DataTable.Columns.Contains(DisplayText))
                    {
                        throw new Exception(String.Format("Object name: {0} \rNo DisplayText column found named: {1}", this.Name, DisplayText));
                    }

                    this.DataSource    = DS.DataTable;
                    this.DisplayMember = this.DisplayText;
                    this.ValueMember   = this.Key;
                    JkLookUpComboBoxList.Add(this);
                }
            }
        }
Пример #2
0
        private void JkDataGridView_EditModeChanged(object sender, EventArgs e)
        {
            foreach (DataGridViewColumn column in this.Columns)
            {
                if (this.Columns[column.Index] is DataGridViewComboBoxColumn)
                {
                    String           controlName = this.DataSet.Columns.Find(c => c.Name == this.Columns[column.Index].DataPropertyName).ControlName;
                    JkLookUpComboBox comboBox    = JkLookUpComboBoxList.FindByName(controlName);
                    JkDataSet        dataSet     = JkDataSetList.FindByName(comboBox.DataSet);

                    if (dataSet.Filtered &&
                        dataSet.Filter != null &&
                        this.EditMode != DataGridViewEditMode.EditProgrammatically &&
                        !String.IsNullOrWhiteSpace(dataSet.Filter))
                    {
                        ((this.Columns[column.Index] as DataGridViewComboBoxColumn).DataSource as DataTable).DefaultView.RowFilter = dataSet.Filter;
                    }
                    else
                    {
                        ((this.Columns[column.Index] as DataGridViewComboBoxColumn).DataSource as DataTable).DefaultView.RowFilter = String.Empty;
                    }
                }
            }
        }