Ejemplo n.º 1
0
        private void AddNewKey()
        {
            NewRow = true;

            foreach (DataGridViewRow a in SelectedDataGridView.Rows)
            {
                if (AvailableDataGridView.SelectedRows.Count > 0 && a.Cells["id"].Value != null && a.Cells["id"].Value.ToString() == AvailableDataGridView.SelectedRows[0].Cells["id"].Value.ToString())
                {
                    NewRow = false;
                }
            }

            if (NewRow)
            {
                DataGridViewRow Row = (DataGridViewRow)AvailableDataGridView.SelectedRows[0].Clone();

                for (int i = 0; i < AvailableDataGridView.SelectedRows[0].Cells.Count; i++)
                {
                    Row.Cells[i].Value = AvailableDataGridView.SelectedRows[0].Cells[i].Value;
                }

                int idx = SelectedDataGridView.Rows.Add(Row);
                //SelectedDataGridView.Rows.Add(AvailableDataGridView[0, AvailableDataGridView.CurrentRow.Index].Value.ToString(), AvailableDataGridView[1, AvailableDataGridView.CurrentRow.Index].Value.ToString());
                NewRow = true;

                SelectedDataGridView.ClearSelection();
                SelectedDataGridView.Rows[idx].Selected = true;

                SelectedDataGridView.Rows[idx].Cells[SelectedDataGridView.Columns.Cast <DataGridViewColumn>().First(x => x.Visible).Name].Selected = true;
            }
        }
Ejemplo n.º 2
0
        private void DataGridView_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button != MouseButtons.Right)
            {
                return;
            }
            var hti = SelectedDataGridView.HitTest(e.X, e.Y);

            if (hti.RowIndex < 0 || SelectedDataGridView.Rows[hti.RowIndex].Selected)
            {
                return;
            }
            SelectedDataGridView.ClearSelection();
            SelectedDataGridView.Rows[hti.RowIndex].Selected = true;
        }
Ejemplo n.º 3
0
        private void AddNewKey()
        {
            NewRow = true;

            foreach (DataGridViewRow a in SelectedDataGridView.Rows)
            {
                if (a.Cells["id"].Value.ToString() == AvailabeDataGridView.CurrentRow.Cells["id"].Value.ToString())
                {
                    NewRow = false;
                }
            }

            if (NewRow)
            {
                int idx = SelectedDataGridView.Rows.Add(AvailabeDataGridView[0, AvailabeDataGridView.CurrentRow.Index].Value.ToString(), AvailabeDataGridView[1, AvailabeDataGridView.CurrentRow.Index].Value.ToString());
                NewRow = true;

                SelectedDataGridView.ClearSelection();
                SelectedDataGridView.Rows[idx].Selected = true;

                SelectedDataGridView.Rows[idx].Cells[SelectedDataGridView.Columns.Cast <DataGridViewColumn>().First(x => x.Visible).Name].Selected = true;
            }
        }