2017-06-22 180 views
3

我有一個ObjectListView上有一些標籤,其中之一是作業號。此作業編號選項卡從數據庫中提取作業編號,並使用每個作業編號旁邊的複選框顯示作業編號。我的要求是,我想在該作業編號選項卡上添加一個複選框。在檢查該複選框時,應該選擇它下面的所有作業編號。即每個工作號碼複選框將被選中.. 有沒有什麼辦法可以實現這個..我會分享一個屏幕截圖作爲參考.. enter image description hereObjectListView選擇所有複選框

+0

你究竟是什麼意思,「它應該選擇下面的所有工作號碼」 ?選擇3135是否會選擇一個較小號碼的所有條目,因此在這種情況下只有3130個?或者是列表順序中的任何條目,在這種情況下,除3130之外的所有條目?無論如何,您爲什麼不處理「檢查」事件,根據選擇檢查每個條目的作業編號並以編程方式選擇它們? –

+0

@ Rev1.0 ..如果你看屏幕截圖,旁邊的工作號碼是一個複選框。我的意思是,如果我點擊工作號碼旁邊的複選框,那麼它應該選擇下面的所有工作號碼.lIke全選 – Ksingh

+0

聽起來像一個奇怪的要求。你確定你需要這個嗎?什麼是用例? –

回答

0

你需要聽取checkitem事件,然後找到哪個事件被檢查,然後檢查下面的這些。 (我認爲具有「工作號碼」>的工作項目比檢查項目低,需要檢查。)

private void objectListView1_ItemChecked(object sender, ItemCheckedEventArgs e) 
{ 
    //First we need to cast the received object to an OLVListItem 
    BrightIdeasSoftware.OLVListItem olvItem = e.Item as BrightIdeasSoftware.OLVListItem; 
    if (olvItem == null) 
     return; //Unable to cast 

    //Now we can cast the RowObject as our class 
    MyClass my = olvItem.RowObject as MyClass; 
    if (my == null) 
     return; //unable to cast 

    //We retrieve the jobnumber. So this is the job number of the item clicked 
    int jobNumber = my.Job; 

    //Now loop through all of our objects in the ObjectListView 
    foreach(var found in objectListView1.Objects) 
    { 
     //cast it to our type of object 
     MyClass mt = found as MyClass; 

     //Compare to our job number, if greater then we check/uncheck the items 
     if (mt.Job > jobNumber) 
     { 
      if (e.Item.Checked) 
       objectListView1.CheckObject(mt); 
      else 
       objectListView1.UncheckObject(mt); 
     } 
    } 
}