private void buttonDown_Click(object sender, EventArgs e) { ColumnsListView colList = CurrentList; if (colList == null) { return; } ColParams colParams = ColumnsLists[colList]; if (colParams == null) { return; } if (colList.SelectedRows.Count == 1) { colList.SuspendLayout(); int row = colList.SelectedRows[0].Index; if (row < colList.Rows.Count - 1) { int col = colList.Columns["OrderIndex"].Index; object a = colList[col, row].Value; object b = colList[col, row + 1].Value; colList[col, row].Value = b; colList[col, row + 1].Value = a; } colList.Sort(colList.Columns["OrderIndex"], ListSortDirection.Ascending); colList.ResumeLayout(); } UpdateButtons(colList, e); }
private void UpdateButtons(object sender, EventArgs e) { bool up = false; bool down = false; ColumnsListView colList = sender as ColumnsListView; if (colList == null) { return; } colList.SuspendLayout(); if (colList.SelectedRows.Count == 1) { DataGridViewRow item = colList.SelectedRows[0]; if (item.Index > 0) { up = true; } if (item.Index < colList.Rows.Count - 1) { down = true; } } colList.ResumeLayout(); if (buttonUp.Enabled != up) { buttonUp.Enabled = up; } if (buttonDown.Enabled != down) { buttonDown.Enabled = down; } }