C# DataGridView 清除所有被選擇列[ClearSelection] / 紀錄和指定選擇列 / 觸發SelectionChanged事件
C# DataGridView 清除所有被選擇列[ClearSelection] / 紀錄和指定選擇列 / 觸發SelectionChanged事件
資料來源: https://dotblogs.com.tw/sam319/2009/12/28/12706
https://docs.microsoft.com/zh-tw/dotnet/api/system.windows.forms.datagridview.clearselection?view=windowsdesktop-6.0
code
public void dgvmain001_SelectionChangedCall() { //--- //觸發dgvmain001_SelectionChanged 正確呼叫 quantityButtonEnableStateSet if (dgvmain001.Rows.Count > 0) { int index = dgvmain001.SelectedRows[0].Index; dgvmain001.ClearSelection(); dgvmain001.Rows[index].Selected = true; } //---觸發dgvmain001_SelectionChanged 正確呼叫 quantityButtonEnableStateSet } private void dgvmain001_SelectionChanged(object sender, EventArgs e) { if (m_intOrderState != 0)//購物車清單項目訂單狀態偵測防呆 { return; } int x, y, row; if (dgvmainArrayIndexGet(out x, out y, out row) != 0) { return; } //判斷項目內容-產品/調味品/折扣讓/小計 //state0 //0[產品] //1[折扣讓] //2[小計] //3[調味品合併] //4[調味品單一] int intState0 = -1; String StrBuf = dgvmain001.Rows[row].Cells[0].Value.ToString(); string[] strs = StrBuf.Split(','); int intIndex = Int32.Parse(strs[0]); int intBuf = Int32.Parse(strs[1]); if (intIndex < 0)//訂單結帳列,直接跳離防呆機制 { return; } if (intBuf >= 0) { //3[調味品合併] //4[調味品單一] if (Int32.Parse(dgvmain001.Rows[row].Cells[4].Value.ToString()) > 1) { intState0 = 3; } else { intState0 = 4; } } else { //0[產品] //1[折扣讓] //2[小計] intState0 = Math.Abs(intBuf) - 1; } m_intDelItemType = intState0; int item_no = m_ShopCart.m_ShopMainList[intIndex].m_intitem_no; String SQL = String.Format("SELECT discount_type,subtotal_flag FROM order_content_data WHERE order_no='{0}' AND item_no='{1}' LIMIT 0,1;", m_StrPosOrderNumber, item_no); DataTable order_content_dataTable = SQLDataTableModel.GetDataTable(SQL); //判斷有折扣/折讓 //state1 0/1 int intState1 = 0;//無 折扣/折讓 //判斷有無小計 //state2 0/1 int intState2 = 0;//無 小計 if (order_content_dataTable.Rows.Count > 0) { if (order_content_dataTable.Rows[0]["discount_type"].ToString() != "N") { intState1 = 1; } if (order_content_dataTable.Rows[0]["subtotal_flag"].ToString() != "N") { intState2 = 1; } } quantityButtonEnableStateSet(intState0, intState1, intState2); if ((intState0 != 1) && (intState0 != 2)) { ShopCartListChangecondimentButtonInitShow();//購物車點選切換調味品選項 } }