Jika anda mendesain tampilan menu form menggunakan ribbonForm dari devexpress anda tentunya akan menghadapi situasi dimana anda tidak ingin semua menu bisa diakses oleh user tertentu, anda ingin membatasi hak menu per user.
Bagi anda yang terbiasa dengan menu standar bawaan VB.NET tentunya hal ini bukanlah hal yang sulit, akan tetapi bagaimana dengan anda yang masih baru dengan devexpress.
Berikut saya sertakan source code looping ribbon control dimulai dari ribbonPageCategory, ribbonGroup, ribbonItem, ribbonItem di dalam subitem.
Source Code dalam C#
using DevExpress.XtraBars;
using DevExpress.XtraBars.Ribbon;
private void simpleButton1_Click(object sender, EventArgs e)
{
foreach (RibbonPage page in ribbonControl1.Pages) {
foreach (RibbonPageGroup group in page.Groups) {
foreach (var link in group.ItemLinks) {
BarItemLink barItemLink = link as BarItemLink;
foreach (BarItemLink baritemlink in group.ItemLinks) {
baritemlink.Visible = true;
}
BarSubItemLink barSubItemLink = link as BarSubItemLink;
if (barSubItemLink != null) {
foreach (BarItemLink itemLink in barSubItemLink.Item.ItemLinks) {
BarButtonItem barButtonItem = itemLink.Item as BarButtonItem;
if(barButtonItem != null)
itemLink.Visible = false;
}
}
}
}
}
}
Source Code dalam VB.NET
Imports DevExpress.XtraBars
Private Sub simpleButton1_Click(sender As Object, e As EventArgs)
For Each page As RibbonPage In ribbonControl1.Pages
For Each group As RibbonPageGroup In page.Groups
For Each link As var In group.ItemLinks
Dim barItemLink__1 As BarItemLink = TryCast(link, BarItemLink)
For Each baritemlink__2 As BarItemLink In group.ItemLinks
baritemlink__2.Visible = True
Next
Dim barSubItemLink As BarSubItemLink = TryCast(link, BarSubItemLink)
If barSubItemLink IsNot Nothing Then
For Each itemLink As BarItemLink In barSubItemLink.Item.ItemLinks
Dim barButtonItem As BarButtonItem = TryCast(itemLink.Item, BarButtonItem)
If barButtonItem IsNot Nothing Then
itemLink.Visible = False
End If
Next
End If
Next
Next
Next
End Sub
Semoga Membantu.
Terimakasih untuk sharing ttg RibbonControl ini,
ReplyDeleteyang saya mau tanya, For Each link As var In group.ItemLinks
"var" itu apa yah???