我在我的项目中有一个编辑按钮,它允许我编辑列表框中的行,但有些行我不想编辑,我该如何做到这一点。如何使列表框中的某些行不可编辑
我想作出第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