|  | 
	                
  
    |  |  
    | 
        
        สอบถามปัญหาเรื่องแปลงค่าจาก Dataset ให้เป็น toolstripmenuItem ครับ     |  
    |  |  
 
              
  
    | 
 
        
          |  |  |  |  |  
          |  |  | 
            
              | Code (VB.NET) 
 Dim Ts As ToolStripMenuItem
Dim ii As Integer
For ii = 0 To dx.Tables("xx").Rows.Count - 1
Ts = CType(dx.Tables("xx").Rows(ii).Item(0), ToolStripItem)
Ts.Visible = True
Next
 จากโค้ดนี้ท้ายสุด
 
 Ts = CType(dx.Tables("xx").Rows(dx.Tables("xx").Rows.Count - 1).Item(0), ToolStripItem)
 
 งั้นอย่า for ให้เมื่อยเลยครับ 5555
 
 ว่าแต่ ToolStripItem นี่เก็บ record data type เป็น อะไรรึครับ
 
 มีตัวอย่างไม๊ครับว่ามันทำได้จริงๆ
 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2016-06-15 16:02:15 | By :
                            lamaka.tor |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ในโค้ดคือตัวอย่างครับ  แล้วที่มาถามคือทำไม่ได้ครับ อยากให้ผู้รู้มาช่วยว่ามันมีแนวทางไหนที่พอจะทำได้บ้าง ถ้าไม่ช่วยก็ไม่น่าจะตอบดีกว่ามั้ยครับ ผมมาขอความช่วยเหลือครับ ขอคนที่อยากช่วยจริงๆครับ ผมจะขอบคุณมาก
 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2016-06-15 16:22:30 | By :
                            punmontha |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
 
        
          |  |  |  |  |  
          |  |  | 
            
              | เอาไปประยุกต์ดูนะครับ 
 
 
 Code (VB.NET)
 
 'It executes during the Form Load and populates all the menu headers. All data are coming from the Backend and there is nothing to hardcode. I have attached the structure of two tables MENUMASTER and ACCESS below.  
 Private Sub MDIParent1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'On Error GoTo ErrHandler
	'Create a Connection class, that has the full features of working with Backend.
	'See article for Connection class :  # 
        Dim Conn As New Conn1
        Dim mnRd As SqlClient.SqlDataReader
	'It helps in populating the MENUs according to user rights. From the Table "Access"
        iUserAccessMode = GlobalValues.lblUsrAccess.Text
        sQry = ""
        sQry = "Select MenuText from MenuMaster Where MainMenuID = 0" & _
               " And MenuID in (Select MenuID from Access Where AccessId = " & CInt(iUserAccessMode) & ")" & _
                " And isActive = 1"
        mnRd = Conn.ReaderData(sQry)
        
	If mnRd.HasRows Then
            mnMenu = New MenuStrip
            While mnRd.Read
                mnMenu.Items.Add(mnRd(0).ToString, Nothing, New System.EventHandler(AddressOf MainMenu_OnClick))
                Me.Controls.Add(mnMenu)
            End While
        End If
        
	mnRd.Close()
    End Sub
'This function creates child menus, when the parent menu was created.
 
    Private Sub MainMenu_OnClick(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim cms As New ContextMenuStrip()
        Dim sMenu() As String
        Dim Conn As New Conn1
        Dim sMenuRD As SqlClient.SqlDataReader
        sQry = ""
        sQry = "Select MenuID from MenuMaster Where MenuText = '" & sender.ToString & "'"
        sMenuRD = Conn.ReaderData(sQry)
        Dim parentMenuID As Integer
        If sMenuRD.HasRows Then
            sMenuRD.Read()
            parentMenuID = sMenuRD("MenuID")
        End If
        sMenuRD.Close()
        sQry = ""
        sQry = "Select MenuText from MenuMaster Where MainMenuID = '" & parentMenuID & "'" & _
               " And isActive = 1" & _
               " And MenuID in (Select MenuID from Access Where AccessId = " & CInt(iUserAccessMode) & ")" & _
               " Order BY MenuOrder"
        sMenuRD = Conn.ReaderData(sQry)
        ReDim Preserve sMenu(0)
        Dim i As Integer
        If sMenuRD.HasRows Then
            ReDim Preserve sMenu(0)
            i = 0
            While sMenuRD.Read()
                ReDim Preserve sMenu(i)
                sMenu(i) = sMenuRD("MenuText")
                i = i + 1
            End While
        End If
        sMenuRD.Close()
        For Each sMn As String In sMenu
            cms.Items.Add(sMn, Nothing, New System.EventHandler(AddressOf SelectedChildMenu_OnClick))
        Next
        Dim tsi As ToolStripMenuItem = CType(sender, ToolStripMenuItem)
        tsi.DropDown = cms
    End Sub
    'This Function is executed at the click event of each menu items, the form to open(FormName) on the execution 
    'of the event is also comes from the backend table "MENUMASTER" 
    Private Sub SelectedChildMenu_OnClick(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim Conn As New Conn1
        Dim sMenuRD As SqlClient.SqlDataReader
        Dim frmName As String = ""
        Dim frm As New Form
        sQry = ""
        sQry = "Select FormName from MenuMaster Where MenuText = '" & sender.ToString & "'"
        sMenuRD = Conn.ReaderData(sQry)
        If sMenuRD.HasRows Then
            sMenuRD.Read()
            frmName = sMenuRD(0).ToString
            DynamicallyLoadedObject(frmName).Show(Me)
        Else
            MsgBox("Under Construction", MsgBoxStyle.Exclamation, "Technical Error")
        End If
        sMenuRD.Close()
    End Sub
    'Importance : High
    'This function helps in converting the string object formName, which is returned from sql into object of type Form
    Private Function DynamicallyLoadedObject(ByVal objectName As String, Optional ByVal args() As Object = Nothing) As Form
        Dim returnObj As Object = Nothing
        Dim Type As Type = Assembly.GetExecutingAssembly().GetType("[YOUR PROJECT NAME]." & objectName)
        If Type IsNot Nothing Then
            returnObj = Activator.CreateInstance(Type, args)
        End If
        Return returnObj
    End Function
 ที่มา
 http://www.codeproject.com/Articles/19223/Dynamic-Creation-Of-MenuStrip-VB-NET
 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2016-06-16 02:37:04 | By :
                            bigsuntat |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  |  |