コード例 #1
0
        private void btnAddField_Click(object sender, EventArgs e)
        {
            try
            {
                DataTable       tempDT          = dgMain.DataSource as DataTable;
                CreateFieldForm createFieldForm = new CreateFieldForm(tempDT, null);
                DialogResult    result          = createFieldForm.ShowDialog();
                if (result.Equals(DialogResult.OK))
                {
                    if (createFieldForm.SelectedRow != null)
                    {
                        DataRow[] selectedRows = tempDT.Select("Field = '" + createFieldForm.SelectedRow["Field"] + "'");
                        if (selectedRows.Length > 0)
                        {
                            selectedRows[0].ItemArray = createFieldForm.SelectedRow.ItemArray;
                        }
                    }
                    else
                    {
                        tempDT = createFieldForm.TempDT;
                    }

                    //dgMain.Rows.Clear();
                    dgMain.DataSource = tempDT;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #2
0
        private void dgMain_DoubleClick(object sender, EventArgs e)
        {
            try
            {
                DataGridViewSelectedRowCollection rows = dgMain.SelectedRows;
                if (rows.Count > 0)
                {
                    DataTable       tempDT      = dgMain.DataSource as DataTable;
                    DataRow         selectedRow = tempDT.NewRow();
                    DataGridViewRow dgRow       = rows[0];
                    Object          NO          = dgRow.Cells["NO"].Value;

                    DataRow[] selectedRows = tempDT.Select("NO = " + NO + "");

                    if (selectedRows.Length > 0)
                    {
                        CreateFieldForm createFieldForm = new CreateFieldForm(tempDT, selectedRows[0]);
                        DialogResult    result          = createFieldForm.ShowDialog();
                        if (result.Equals(DialogResult.OK))
                        {
                            DataRow[] tempRows = tempDT.Select("Field = '" + createFieldForm.SelectedRow["Field"] + "'");
                            if (tempRows.Length > 0)
                            {
                                tempRows[0].ItemArray = createFieldForm.SelectedRow.ItemArray;
                            }
                            dgMain.DataSource = tempDT;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }