引用问题

jsfeiyu 2003-09-14 09:25:42
我要做一个控制菜单权限的功能,有一段代码如下,系统提示" & menuname & ".enabled = True这句错误,menuname代表菜单项的名称,请问如何才可行!
Dim cmd As SqlClient.SqlCommand
Dim dra As SqlClient.SqlDataReader
Dim strsql As String
Dim menuname As String
cmd = New SqlClient.SqlCommand()
cmd.Connection = New SqlClient.SqlConnection("data source=" & pub_server & ";initial catalog=" & pub_database & ";integrated security=SSPI")
strsql = "select menuname,running from menulist,userauthority where menulist.menucode=userauthority.programid and userid='" & pub_name & "'"
cmd.CommandText = strsql
cmd.Connection.Open()
dra = cmd.ExecuteReader
While dra.Read
menuname = Trim(dra(0))
If dra(1) = "T" Then
" & menuname & ".enabled = True
Else
" & menuname & ".enabled = false
End If
End While
...全文
39 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
szch 2003-09-15
  • 打赏
  • 举报
回复
menuitem不能直接用name,但你可以用text判断
dim c as menuitem
for each c in me.menu1
If c.text = dra(0) Then
If dra(1) = "T" Then
c.Enabled = True
Else
c.Enabled = False
End If
End If
next
xixigongzhu 2003-09-15
  • 打赏
  • 举报
回复
dim fi As FieldInfo = Me.GetType().GetField(menuname)
dim menu As Control = fi.GetValue(Me)
menu.Enabled = (dra(1) = "T")
banni2003 2003-09-15
  • 打赏
  • 举报
回复
把 dim c as menuitem 改为 Dim c As Control

For Each c In menuitem.Controls
If c.Name = dra(0) Then
If dra(1) = "T" Then
c.Enabled = True
Else
c.Enabled = False
End If
End If
Next
CloneCenter 2003-09-15
  • 打赏
  • 举报
回复
其他级别下的菜单用递归的方法来处理。MenuItem.menuItems(i),方法相同。可以考虑使用 Index,这样是防止菜单中的文字有重复的。
jsfeiyu 2003-09-15
  • 打赏
  • 举报
回复
郁闷,用灏然的方法,只能控制到顶级菜单,下面的子菜单没用!
jsfeiyu 2003-09-14
  • 打赏
  • 举报
回复
For Each c In Me.MainMenu1
If c.Name = dra(0) Then
If dra(1) = "T" Then
c.Enabled = True
Else
c.Enabled = False
End If
End If
Next
还是没用啊,在Me.MainMenu1时出错,错误提示为:该类型不是集合类型!
ArLi2003 2003-09-14
  • 打赏
  • 举报
回复
if menuname* parent is menu1 u can replace Me.Controls to me.menu1

'ex:

Dim c As System.Windows.Forms.Control
For Each c In Me.menu1
If c.Name = menuname Then c.Enabled = False
Next
ArLi2003 2003-09-14
  • 打赏
  • 举报
回复
//C#

foreach (System.Windows.Forms.Control c in this.Controls) {
if (c.Name == menuname{
c.Enabled = false;
}
}

'VB.net

Dim c As System.Windows.Forms.Control
For Each c In Me.Controls
If c.Name = menuname Then c.Enabled = False
Next

16,553

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧