2015-05-02 64 views
0

我有一點問題。我有一個ListView,名爲lstPers,有4列。我想要做的是禁用編輯欄中的文字。所以我發現在計算器上列表視圖列錯誤

lstPers.Columns["Nume persoana"].ReadOnly = true; 

此命令,但它給出了這樣的錯誤:

"System.Windows.Forms.ColumnHeader' does not contain a definition for 'ReadOnly' and no extension method 'ReadOnly' accepting a first argument of type 'System.Windows.Forms.ColumnHeader' could be found (are you missing a using directive or an assembly reference?)"

我一直在尋找的引用,但在沒有運氣。任何人都可以請幫我嗎?

+0

你在哪裏運行這段代碼?在Form類中還是在不同的類中? – Steve

+0

以勝利的形式。以下是創建ListView列的代碼。 (不是完整的代碼) //將子子項附加到ListView lstPers.Columns.Add(「Nume persoana」,200,Horizo​​ntalAlignment.Left); lstPers.Columns.Add(「CNP」,120,Horizo​​ntalAlignment.Left);lstPers.Columns.Add(「Data nasterii」,100,Horizo​​ntalAlignment.Left); lstPers.Columns.Add(「Profesia」,150,Horizo​​ntalAlignment.Left); lstPers.Columns.Add(「Adresa」,250,Horizo​​ntalAlignment.Left);「 –

+0

創建列表視圖,效果很好,只需要一點點tweek就可以使其成爲只讀。 –

回答

2

要禁用編輯Items使用這樣的:

lstPers.LabelEdit = false; 

注意,在一個Winforms Listview所有其他ColumnsSubItems)不能無論如何編輯。

+0

Thank you @TaW。Works good。Owe你太棒了! –

0

ListView.Columns屬性只給出列標題。

也許你想要DataGridView控件?它的Columns屬性爲您提供了整個列,並且這些列具有ReadOnly屬性。您也可以通過設計人員設置其ReadOnly屬性。

+0

這很好,TaW的方法運作良好。謝謝你們倆 –