0

我的项目中有一个编辑按钮,它允许我编辑列表框中的行,但是我不想编辑某些行,我怎样才能做到这一点。

我想让第 4、9、14、19、24、29、34、39、44、49、54、59、64、69、74、79、84、89、94、99 行不可编辑。

我希望 applicationdate 行不可编辑,有没有办法可以使该行代码不可编辑。

4

2 回答 2

0

处理SelectedIndexChanged事件。每次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
于 2012-08-12T08:00:23.810 回答
-1
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
于 2012-08-12T09:07:20.140 回答