我在我的項目中有一個編輯按鈕,它允許我編輯列表框中的行,但有些行我不想編輯,我該如何做到這一點。如何使列表框中的某些行不可編輯
我想作出第4,9,14,19,24,29,34,39,44,49,54,59,64,69,74,79,84,94,99的第4行,編輯。
我想applicationdate行是不可編輯的,有沒有辦法讓我的代碼行不可編輯。
我在我的項目中有一個編輯按鈕,它允許我編輯列表框中的行,但有些行我不想編輯,我該如何做到這一點。如何使列表框中的某些行不可編輯
我想作出第4,9,14,19,24,29,34,39,44,49,54,59,64,69,74,79,84,94,99的第4行,編輯。
我想applicationdate行是不可編輯的,有沒有辦法讓我的代碼行不可編輯。
處理SelectedIndexChanged
event。每次ListBox
控件中的項目選擇更改時都會引發此事件。
在此事件的事件處理程序方法中,檢查當前選定項目的索引。如果它是您想要編輯的文件,請啓用編輯按鈕。否則,禁用編輯按鈕。
例如:
Private Sub myListBox_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles myListBox.SelectedIndexChanged
' Only allow editing of items with an odd-numbered index.
' (This isn't very useful, just a demonstration. You can use any criteria you
' want to determine whether editing should be allowed for the current item.)
btnEdit.Enabled = myListBox.SelectedIndex Mod 2
End Sub
Private Sub myListBox_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles myListBox.SelectedIndexChanged
' Only allow editing of items with an odd-numbered index.
' (This isn't very useful, just a demonstration. You can use any criteria you
' want to determine whether editing should be allowed for the current item.)
Dim unedit() as integer={4, 9, 14, 19, 24, 29, 34, 39, 44, 49, 54, 59, 64, 69, 74, 79, 84, 89, 94, 99}
dim i as integer
for i = 0 unedit.count-1
if myListBox.SelectedIndex=unedit(i) then
btnEdit.Enabled = false
exit for
end if
End Sub
使用此代碼行1,5,9是不可編輯的,它顯示每4行不可編輯。 – nurafh 2012-08-12 09:27:41
對不起,我搞砸了代碼。請再檢查一次。更新答案 – 2012-08-13 13:03:54
感謝科迪灰色,幫助我一下,現在我只需要工作如何得到它的,我想一定行工作。 – nurafh 2012-08-12 08:47:11