Quantcast
Channel: Windows Forms General forum
Viewing all articles
Browse latest Browse all 12583

dynamically load menustrip as per user permission

$
0
0

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

Public Sub FillDGVuser()
        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()
    End Sub

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

            If Me.DGVuser.Rows(i).Cells("edit").Value = "NO" 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

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

kindly help me for this

i will be very thankfull to u all






Viewing all articles
Browse latest Browse all 12583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>