DX控制元件迴圈找控制元件
阿新 • • 發佈:2019-01-27
1、Ribbon迴圈查詢 RibbonPage---RibbonPageGroup---BarButtonItem
foreach (RibbonPage rPage in RPage_Home.Collection)
{
foreach (RibbonPageGroup rpg in rPage.Groups)
{
foreach (var btn in rpg.Ribbon.Items)
{
if (btn is BarButtonItem)
{
BarButtonItem btnBar = btn as BarButtonItem;
if (btnBar.Name.ToString() == strBtnRpg)
{
btnBar.Visibility = DevExpress.XtraBars.BarItemVisibility.Always;
}
}
}
}
} 2、迴圈在layoutControlGroup裡的LayoutControlItem sumItems[i]為一組控制元件名的集合(TextBox)
foreach (DevExpress.XtraLayout.LayoutControlItem item in layoutControlGroup02.Items)
{
if (item.ControlName == sumItems[i])
{
item.Control.BackColor = Color.LightSalmon;
values += item.Control.Text + "-";
}
}
foreach (DevExpress.XtraLayout.LayoutControlItem item in layoutControlGroup01.Items)
{
if (item.Control is TextEdit)
{
item.Control.Text = "";
}
} 3、取出表中一行資料,迴圈賦值給LayoutControlItem中的TextEdit
DataRow dr = dt.Rows[0];
for (int i = 0; i < dr.ItemArray.Length; i++)
{
foreach (DevExpress.XtraLayout.LayoutControlItem item in layoutControlGroup01.Items)
{
if (item.Text==dr.Table.Columns[i].ColumnName.ToString())
{
item.Control.Text = dr[dr.Table.Columns[i].ColumnName.ToString()].ToString();
}
}
} 4、將介面的LayoutControlItem中的TextEdit的資料迴圈賦值給特定行
//插入所有資料
for (int i = 0; i < dr.ItemArray.Length; i++)
{
foreach (DevExpress.XtraLayout.LayoutControlItem item in layoutControlGroup01.Items)
{
if (item.Text==dr.Table.Columns[i].ColumnName.ToString())
{
dr[dr.Table.Columns[i].ColumnName.ToString()] = item.Control.Text;
break;
}
}
foreach (DevExpress.XtraLayout.LayoutControlItem item in layoutControlGroup02.Items)
{
if (item.Text==dr.Table.Columns[i].ColumnName.ToString())
{
dr[dr.Table.Columns[i].ColumnName.ToString()] = item.Control.Text;
break;
}
}
foreach (DevExpress.XtraLayout.LayoutControlItem item in layoutControlGroup04.Items)
{
if (item.Text==dr.Table.Columns[i].ColumnName.ToString())
{
dr[dr.Table.Columns[i].ColumnName.ToString()] = item.Control.Text;
break;
}
}
} 5.How to loop through all ribbon tabs, ribbon bar and items on WinForms Ribbon control
If you need to loop through all ribbon tabs, ribbon bars and items on each ribbon bar here is how to do it. C#:
foreach (BaseItem item in ribbonControl1.Items)
{
RibbonTabItem ribbonTab = item as RibbonTabItem;
if (ribbonTab != null)
{
RibbonPanel panel = ribbonTab.Panel;
foreach (Control panelControl in panel.Controls)
{
RibbonBar ribbonBar = panelControl as RibbonBar;
if (ribbonBar != null)
{
// At this point you can simply disable each RibbonBar and that will //disable all items on it
//ribbonBar.Enabled = false;
// Here is how you loop through items on RibbonBar
foreach (BaseItem ribbonBarItem in ribbonBar.Items)
{
ribbonBarItem.Enabled = false;
}
}
}
}
}
foreach (RibbonPage rPage in RPage_Home.Collection)
{
foreach (RibbonPageGroup rpg in rPage.Groups)
{
foreach (var btn in rpg.Ribbon.Items)
{
if (btn is BarButtonItem)
{
BarButtonItem btnBar = btn as BarButtonItem;
if (btnBar.Name.ToString() == strBtnRpg)
{
btnBar.Visibility = DevExpress.XtraBars.BarItemVisibility.Always;
}
}
}
}
} 2、迴圈在layoutControlGroup裡的LayoutControlItem sumItems[i]為一組控制元件名的集合(TextBox)
foreach (DevExpress.XtraLayout.LayoutControlItem item in layoutControlGroup02.Items)
{
if (item.ControlName == sumItems[i])
{
item.Control.BackColor = Color.LightSalmon;
values += item.Control.Text + "-";
}
}
foreach (DevExpress.XtraLayout.LayoutControlItem item in layoutControlGroup01.Items)
{
if (item.Control is TextEdit)
{
item.Control.Text = "";
}
} 3、取出表中一行資料,迴圈賦值給LayoutControlItem中的TextEdit
DataRow dr = dt.Rows[0];
for (int i = 0; i < dr.ItemArray.Length; i++)
{
foreach (DevExpress.XtraLayout.LayoutControlItem item in layoutControlGroup01.Items)
{
if (item.Text==dr.Table.Columns[i].ColumnName.ToString())
{
item.Control.Text = dr[dr.Table.Columns[i].ColumnName.ToString()].ToString();
}
}
} 4、將介面的LayoutControlItem中的TextEdit的資料迴圈賦值給特定行
//插入所有資料
for (int i = 0; i < dr.ItemArray.Length; i++)
{
foreach (DevExpress.XtraLayout.LayoutControlItem item in layoutControlGroup01.Items)
{
if (item.Text==dr.Table.Columns[i].ColumnName.ToString())
{
dr[dr.Table.Columns[i].ColumnName.ToString()] = item.Control.Text;
break;
}
}
foreach (DevExpress.XtraLayout.LayoutControlItem item in layoutControlGroup02.Items)
{
if (item.Text==dr.Table.Columns[i].ColumnName.ToString())
{
dr[dr.Table.Columns[i].ColumnName.ToString()] = item.Control.Text;
break;
}
}
foreach (DevExpress.XtraLayout.LayoutControlItem item in layoutControlGroup04.Items)
{
if (item.Text==dr.Table.Columns[i].ColumnName.ToString())
{
dr[dr.Table.Columns[i].ColumnName.ToString()] = item.Control.Text;
break;
}
}
} 5.How to loop through all ribbon tabs, ribbon bar and items on WinForms Ribbon control
If you need to loop through all ribbon tabs, ribbon bars and items on each ribbon bar here is how to do it. C#:
foreach (BaseItem item in ribbonControl1.Items)
{
RibbonTabItem ribbonTab = item as RibbonTabItem;
if (ribbonTab != null)
{
RibbonPanel panel = ribbonTab.Panel;
foreach (Control panelControl in panel.Controls)
{
RibbonBar ribbonBar = panelControl as RibbonBar;
if (ribbonBar != null)
{
// At this point you can simply disable each RibbonBar and that will //disable all items on it
//ribbonBar.Enabled = false;
// Here is how you loop through items on RibbonBar
foreach (BaseItem ribbonBarItem in ribbonBar.Items)
{
ribbonBarItem.Enabled = false;
}
}
}
}
}