hi to all,
i have an menustrip in the form MAIN
i want to load menustripitems as per the user permission given in the tbluser database table which load during form load event in datagridview

DataAdapter1 = New SqlDataAdapter("Select * From tbluser WHERE userID = '" & txtuserid.Text & "' ORDER BY userID", Conn)
        DataSet1.Clear()
        DataAdapter1.Fill(DataSet1, "tbluser")
        DGVuser.DataSource = DataSet1.Tables(0)
        DGVuser.Refresh()

the table having columns with menustrip name

i am trying to short menustripitem by these code:

Public Sub Fillmenustrip()

        For i As Integer = 0 To DGVuser.Rows.Count - 1
            If Me.DGVuser.Rows(i).Cells("marit").Value = "NO" Then
                MenuStrip1.Items("REGTool").Visible = False
            Else
                MenuStrip1.Items("REGTool").Visible = True
            End If
            If Me.DGVuser.Rows(i).Cells("maritBA").Value = "NO" Then
                CType(MenuStrip1.Items("REGTool"), ToolStripMenuItem).DropDownItems("regBAI").Visible = False
            Else
                CType(MenuStrip1.Items("REGTool"), ToolStripMenuItem).DropDownItems("regBAI").Visible = True
            End If
            If Me.DGVuser.Rows(i).Cells("maritMA").Value = "NO" Then
                CType(MenuStrip1.Items("REGTool"), ToolStripMenuItem).DropDownItems("regMAI").Visible = False
            Else
                CType(MenuStrip1.Items("REGTool"), ToolStripMenuItem).DropDownItems("regMAI").Visible = True
            End If
            If Me.DGVuser.Rows(i).Cells("maritBSc").Value = "NO" Then
                CType(MenuStrip1.Items("REGTool"), ToolStripMenuItem).DropDownItems("regBScI").Visible = False
            Else
                CType(MenuStrip1.Items("REGTool"), ToolStripMenuItem).DropDownItems("regBScI").Visible = True
            End If
        Next
        For i As Integer = 0 To DGVuser.Rows.Count - 1
            If Me.DGVuser.Rows(i).Cells("admission").Value = "YES".ToString Then
                MenuStrip1.Items("ADTool").Visible = True
            Else
                MenuStrip1.Items("ADTool").Visible = False
            End If
        Next
        For i As Integer = 0 To DGVuser.Rows.Count - 1
            If Me.DGVuser.Rows(i).Cells("admissionBA1").Value = "NO".ToString Then
                CType(MenuStrip1.Items("ADTool"), ToolStripMenuItem).DropDownItems("adBAI").Enabled = False
            ElseIf Me.DGVuser.Rows(i).Cells("admissionBA1").Value = "YES".ToString Then
                CType(MenuStrip1.Items("ADTool"), ToolStripMenuItem).DropDownItems("adBAI").Enabled = True
            End If
        Next
        For i As Integer = 0 To DGVuser.Rows.Count - 1
            If Me.DGVuser.Rows(i).Cells("admissionBA2").Value = "NO".ToString Then
                CType(MenuStrip1.Items("ADTool"), ToolStripMenuItem).DropDownItems("adBAII").Enabled = False
            ElseIf Me.DGVuser.Rows(i).Cells("admissionBA2").Value = "YES".ToString Then
                CType(MenuStrip1.Items("ADTool"), ToolStripMenuItem).DropDownItems("adBAII").Enabled = True
            End If
        Next
        For i As Integer = 0 To DGVuser.Rows.Count - 1
            If Me.DGVuser.Rows(i).Cells("admissionBA3").Value = "NO".ToString Then
                CType(MenuStrip1.Items("ADTool"), ToolStripMenuItem).DropDownItems("adBAIII").Enabled = False
            ElseIf Me.DGVuser.Rows(i).Cells("admissionBA3").Value = "YES".ToString Then
                CType(MenuStrip1.Items("ADTool"), ToolStripMenuItem).DropDownItems("adBAIII").Enabled = True
            End If
        Next

    End Sub

it works for only marit but not for other i.e ADTool

kindly help me for this

i changed it with:

Public Sub Fillmenustrip()
        For i As Integer = 0 To DGVuser.Rows.Count - 1
            If Me.DGVuser.Rows(i).Cells("marit").Value = "NO" Then
                MenuStrip1.Items("REGTool").Visible = False
            Else
                MenuStrip1.Items("REGTool").Visible = True
            End If
            If Me.DGVuser.Rows(i).Cells("maritBA").Value = "NO" Then
                CType(MenuStrip1.Items("REGTool"), ToolStripMenuItem).DropDownItems("regBAI").Visible = False
            Else
                CType(MenuStrip1.Items("REGTool"), ToolStripMenuItem).DropDownItems("regBAI").Visible = True
            End If
            If Me.DGVuser.Rows(i).Cells("maritMA").Value = "NO" Then
                CType(MenuStrip1.Items("REGTool"), ToolStripMenuItem).DropDownItems("regMAI").Visible = False
            Else
                CType(MenuStrip1.Items("REGTool"), ToolStripMenuItem).DropDownItems("regMAI").Visible = True
            End If
            If Me.DGVuser.Rows(i).Cells("maritBSc").Value = "NO" Then
                CType(MenuStrip1.Items("REGTool"), ToolStripMenuItem).DropDownItems("regBScI").Visible = False
            Else
                CType(MenuStrip1.Items("REGTool"), ToolStripMenuItem).DropDownItems("regBScI").Visible = True
            End If

            If Me.DGVuser.Rows(i).Cells("edit").Value = "YES" Then
                MenuStrip1.Items("EDITDETAILTool").Visible = False
            Else
                MenuStrip1.Items("EDITDETAILTool").Visible = True
            End If
            If Me.DGVuser.Rows(i).Cells("editBA").Value = "NO" Then
                CType(MenuStrip1.Items("EDITDETAILTool"), ToolStripMenuItem).DropDownItems("EDITDETAILBATool").Visible = False
            Else
                CType(MenuStrip1.Items("EDITDETAILTool"), ToolStripMenuItem).DropDownItems("EDITDETAILBATool").Visible = True
            End If
            If Me.DGVuser.Rows(i).Cells("editMA").Value = "NO" Then
                CType(MenuStrip1.Items("EDITDETAILTool"), ToolStripMenuItem).DropDownItems("EDITDETAILMATool").Visible = False
            Else
                CType(MenuStrip1.Items("EDITDETAILTool"), ToolStripMenuItem).DropDownItems("EDITDETAILMATool").Visible = True
            End If
            If Me.DGVuser.Rows(i).Cells("editBSc").Value = "NO" Then
                CType(MenuStrip1.Items("EDITDETAILTool"), ToolStripMenuItem).DropDownItems("EDITDETAILBScTool").Visible = False
            Else
                CType(MenuStrip1.Items("EDITDETAILTool"), ToolStripMenuItem).DropDownItems("EDITDETAILBScTool").Visible = True
            End If
        Next

    End Sub

but now edit menustripitems show contineouslly

please help me for this
i will be very thankfull to u all

Hi, did you find the solution?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.