private void butDown_Click(object sender,EventArgs e) { if(textFind.Text!=""){ MsgBox.Show(this,"Not allowed unless search text is empty."); return; } if(!comboSuppliers.IsAllSelected){ MsgBox.Show(this,"Not allowed unless All suppliers are selected."); return; } List<int> listSelected=gridMain.SelectedIndices.ToList<int>(); if(listSelected.Count==0){ MsgBox.Show(this,"Please select at least one supply, first."); return; } for(int i=1;i<listSelected.Count;i++) { if(_listSupplies[listSelected[0]].Category != _listSupplies[listSelected[i]].Category){ MsgBox.Show(this,"All selected supplies must be in the same category."); return; } if(listSelected[i-1]+1 != listSelected[i]){ MsgBox.Show(this,"Selection must not have gaps.");//makes my math too hard return; } } if(listSelected[listSelected.Count-1]==_listSupplies.Count-1){ return;//already at bottom } if(_listSupplies[listSelected[listSelected.Count-1]].Category != _listSupplies[listSelected[listSelected.Count-1]+1].Category){ MsgBox.Show(this,"Already at bottom of category."); return; } int countMove=_listSupplies[listSelected[listSelected.Count-1]+1].ItemOrder-_listSupplies[listSelected[listSelected.Count-1]].ItemOrder;//example 5-4=1 List<long> listSupplyNums=new List<long>(); for(int i=0;i<listSelected.Count;i++) { listSupplyNums.Add(_listSupplies[listSelected[i]].SupplyNum); } Supplies.OrderAdd(listSupplyNums,countMove); _listSupplies[listSelected[listSelected.Count-1]+1].ItemOrder -=listSelected.Count+countMove-1;//Example 5-5+1-1=0, while the 5 selected items moved down to occupy 1 through 5. Supplies.Update(_listSupplies[listSelected[listSelected.Count-1]+1]); FillGrid(); int[] indicesNew=new int[listSelected.Count]; for(int i=0;i<listSelected.Count;i++){ indicesNew[i]=listSelected[i]+1; } gridMain.SetSelected(indicesNew,true); }