コード例 #1
0
        public void FillDgvSubjectsCombo()
        {
            CommonSP  stud = new CommonSP();
            DataTable dt   = new DataTable();

            dt = stud.FillSubjectsCombo();
            DataRow drow = dt.NewRow();

            dt.Rows.InsertAt(drow, 0);

            dgvsubject.DataSource    = dt;
            dgvsubject.ValueMember   = "subject_id";
            dgvsubject.DisplayMember = "subjectName";
        }
コード例 #2
0
        /// <summary>
        ///  dgvGrading grid cell begin edit for Combo box subject fill and remove from the list once it has selected
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dgvGrading_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
        {
            try
            {
                if (dgvGrading.RowCount > 1)
                {
                    DataTable dtbl       = new DataTable();
                    CommonSP  subjectsSp = new CommonSP();

                    if (dgvGrading.CurrentCell.ColumnIndex == dgvGrading.Columns["dgvsubject"].Index)
                    {
                        dtbl = subjectsSp.FillSubjectsCombo();
                        if (dtbl.Rows.Count > 0)
                        {
                            if (dgvGrading.RowCount > 1)
                            {
                                int inGridRowCount = dgvGrading.RowCount;
                                for (int inI = 0; inI < inGridRowCount - 1; inI++)
                                {
                                    if (inI != e.RowIndex)
                                    {
                                        int inTableRowcount = dtbl.Rows.Count;
                                        for (int inJ = 0; inJ < inTableRowcount; inJ++)
                                        {
                                            if (dgvGrading.Rows[inI].Cells["dgvsubject"].Value != null && dgvGrading.Rows[inI].Cells["dgvsubject"].Value.ToString() != string.Empty)
                                            {
                                                if (dtbl.Rows[inJ]["subject_id"].ToString() == dgvGrading.Rows[inI].Cells["dgvsubject"].Value.ToString())
                                                {
                                                    dtbl.Rows.RemoveAt(inJ);
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            DataGridViewComboBoxCell dgvccSubject = (DataGridViewComboBoxCell)dgvGrading[dgvGrading.Columns["dgvsubject"].Index, e.RowIndex];
                            dgvccSubject.DataSource    = dtbl;
                            dgvccSubject.ValueMember   = "subject_id";
                            dgvccSubject.DisplayMember = "subjectName";
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }