2014-01-29 135 views
0

我有一個dataTreeListView作爲添加到它如下這已經得到了當場打死列標題:ObjectListView重新排序列

oCol2.IsVisible = false; 
dataTreeListView.AllColumns.AddRange(new OLVColumn[] { oCol1, oCol2, oCol3, oCol4, oCol5}); 

dataTreeListView.KeyAspectName = id; 
dataTreeListView.ParentKeyAspectName = ParentId; 
dataTreeListView.DataSource = list; 
dataTreeListView.RootKeyValue = 0; 

名單本身已經得到了7種性質(包括IdParentId)。

我試圖實現的是,在selectedIndex更改組合框時,列標題將改變位置。

From View (type1) (oCol2.IsVisible = false): 
oCol1 (expandable) | oCol2 (hidden) | oCol3 | oCol4 | oCol5 

To View (type2) (oCol2.IsVisible = true): 
oCol2 | oCol1 (expandable) | oCol3 | oCol4 | oCol5 

我現在得到的是視圖(TYPE1)工作正常,但切換到查看TYPE2後,可擴展柱仍處於oCol1而不是oCol2。看來,我不能switch的主要欄目。

對此有何幫助?

+0

的2型視圖,然後再oCol1(可擴展)定義oCol2。根據你的問題,這看起來像一個預期的輸出。除非我錯過任何東西。 –

+0

嗨theghostofc,我試圖做這樣的事情。 dataTreeListView.AllColumns.Clear(); oCol2.IsVisible = true; dataTreeListView.AllColumns.AddRange(new OLVColumn [] {oCol2,oCol1,oCol3,oCol4,oCol5,}); 結果仍然是一樣的,第一列的oCol1 – user3167398

回答

0

如果您只是想更改順序,請更改每列的DisplayIndex屬性。

如果要隱藏/顯示列(以及重新排列它們),請更改AllColumns的內容,然後致電RebuildColumns()。見this FAQ

如果你想各種列布局之間切換,可以使用SaveState()RestoreState()this recipe

+0

您好Grammarian,我已經使用另一種方法來處理我的數據顯示,謝謝! – user3167398