DataGridView兩列進行互換的源碼

private void toolLeft2_Click(object sender, EventArgs e)
        {
            int selcol = DBGrid2.CurrentCell.ColumnIndex;
            int selrow = DBGrid2.CurrentCell.RowIndex;
            DataGridViewColumn col = (DataGridViewColumn)DBGrid2.Columns[selcol].Clone();
            DBGrid2.Columns.Insert(DBGrid2.CurrentCell.ColumnIndex - 1, col);
            DBGrid2.Columns.RemoveAt(selcol + 1);
            DBGrid2.CurrentCell = DBGrid2.Rows[selrow].Cells[selcol - 1];
        }

        private void toolRight2_Click(object sender, EventArgs e)
        {
            int selcol = DBGrid2.CurrentCell.ColumnIndex;
            int selrow = DBGrid2.CurrentCell.RowIndex;
            DataGridViewColumn col = (DataGridViewColumn)DBGrid2.Columns[selcol].Clone();
            DBGrid2.Columns.Insert(DBGrid2.CurrentCell.ColumnIndex + 2, col);
            DBGrid2.Columns.RemoveAt(selcol);
            DBGrid2.CurrentCell = DBGrid2.Rows[selrow].Cells[selcol + 1];
        }

        private void DBGrid2_SelectionChanged(object sender, EventArgs e)
        {
            if (DBGrid2.CurrentCell == null) return;
            if (DBGrid2.CurrentCell.ColumnIndex <= 1 || DBGrid2.CurrentCell.ColumnIndex >= DBGrid2.ColumnCount - 1)
            {
                toolLeft2.Enabled = false;
                toolRight2.Enabled = false;
            }
            else if (DBGrid2.CurrentCell.ColumnIndex == 2)
            {
                toolLeft2.Enabled = false;
                if (DBGrid2.CurrentCell.ColumnIndex == DBGrid2.ColumnCount - 2)
                    toolRight2.Enabled = false;
                else
                    toolRight2.Enabled = true;
            }
            else
            {
                toolLeft2.Enabled = true;
                if (DBGrid2.CurrentCell.ColumnIndex == DBGrid2.ColumnCount - 2)
                    toolRight2.Enabled = false;
                else
                    toolRight2.Enabled = true;
            }
        }

     

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章