コード例 #1
0
        private void dgv_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            DataGridView dgv = (DataGridView)sender;
            object       val = dgv.Rows[e.RowIndex].Cells[1].Value;

            if (val == null || string.IsNullOrEmpty(val.ToString()))
            {
                return;
            }

            Citizen citizen = null;

            if (CitizenExtensions.CitizenById(val.ToString(), out citizen))
            {
                Preview prev = new Preview();
                prev.AcceptDetails(citizen);
                prev.FormClosed += (ss, ee) => { Enabled = true; };
                Enabled          = false;
                prev.Show();
                return;
            }
            MessageBox.Show("Entry not found");
        }
コード例 #2
0
        private void dataGrid_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            DataGridView view  = (DataGridView)sender;
            object       value = view.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;

            if (value == null || string.IsNullOrEmpty(value.ToString().Trim(' ')))
            {
                /// in case someone deleted a row content
                if (view.RowCount > 1)
                {
                    view.Rows.RemoveAt(e.RowIndex);
                }
                return;
            }

            Citizen citizen;

            if (CitizenExtensions.CitizenFound(value.ToString(), out citizen))
            {
                view.Rows[e.RowIndex].Cells[1].Value = citizen.IdNumber;
                return;
            }
            view.Rows[e.RowIndex].Cells[1].Value = NotRegisteredId;
        }