<pre name="code" class="html">//查询前记录选中行 int _currentRow = 0; //int _currentColumn = 0; switch (modMark) { case 1: if (dgvHis.CurrentCell != null) { _currentRow = this.dgvHis.CurrentCell.RowIndex; //_currentColumn = this.dgvHis.CurrentCell.ColumnIndex ; } break; case 2: if (dgvBank.CurrentCell != null) { _currentRow = this.dgvBank.CurrentCell.RowIndex; //_currentColumn = this.dgvBank.CurrentCell.ColumnIndex; } break; } //设置选中行 switch (modMark) { case 1: if (dgvHis.Rows.Count > 0) { if (dgvHis.Rows.Count >= _currentRow) { dgvHis.Rows[_currentRow].Selected = true; dgvHis.FirstDisplayedScrollingRowIndex = _currentRow; } else { dgvHis.Rows[dgvHis.Rows.Count - 1].Selected = true; dgvHis.FirstDisplayedScrollingRowIndex = dgvHis.Rows.Count - 1; } } // if (dgvHis.Columns.Count > _currentColumn) // { // dgvHis.Columns[_currentColumn].Selected = true; // } // else // { // dgvHis.Columns[dgvHis.Columns.Count - 1].Selected = true; // } break; case 2: if (dgvBank.Rows.Count > 0) { if (dgvBank.Rows.Count >= _currentRow) { dgvBank.Rows[_currentRow].Selected = true; dgvBank.FirstDisplayedScrollingRowIndex = _currentRow; } else { dgvBank.Rows[dgvBank.Rows.Count - 1].Selected = true; dgvBank.FirstDisplayedScrollingRowIndex = dgvBank.Rows.Count - 1; } } // if (dgvBank.Columns.Count > _currentColumn) // { // dgvBank.Columns[_currentColumn].Selected = true; // } // else // { // dgvBank.Columns[dgvBank.Columns.Count - 1].Selected = true; // } break; }
时间: 2024-09-17 04:18:41