admin 管理员组文章数量: 887021
2023年12月18日发(作者:英翻中文在线翻译拍照)
DevExpressGridView使用大全
一、ComboBoxEdit
1、 如何使其不可编辑
TextEditStyle设置为:DisableTextEditor
2、 如何设置鼠标为手形
Cursor 设置为:Hand
二、GridControl
1、 如何解决单击记录整行选中的问题
View->OptionsBehavior->EditorShowMode设置为:Click
2、 如何新增一条记录
(1)、gridVwRow()
(2)、实现gridView_InitNewRow事件
3、如何解决GridControl记录能获取而没有显示出来的问题
gridVateColumns();
4、如何让行只能选择而不能编辑(或编辑某一单元格)
(1)、View->OptionsBehavior->EditorShowMode设置为:Click
(2)、View->OptionsBehavior->Editable 设置为:false
5、如何禁用GridControl中单击列弹出右键菜单
设置Run Design->OptionsMenu->EnableColumnMenu设置为:false
6、如何隐藏GridControl的GroupPanel表头
设置Run Design->OptionsView->ShowGroupPanel设置为:false
7、如何禁用GridControl中列头的过滤器
过滤器如下图所示:
设置 Run Design->OptionsCustomization->AllowFilter设置为:false
8、如何在查询得到0条记录时显示自定义的字符提示/显示
如图所示:
方法如下:
//When no Records Are Being Displayed
privatevoid gridView1_CustomDrawEmptyForeground(object sender,
CustomDrawEventArgs e)
{
//方法一(此方法为GridView设置了数据源绑定时,可用)
ColumnView columnView = sender as ColumnView;
BindingSource bindingSource = ource as
BindingSource;
if(bindingSou == 0)
{
string str = "没有查询到你所想要的数据!";
Font f = new Font("宋体", 10, FontS);
Rectangle r = new Rectangle( + 5, + 5,
- 5, t - 5);
tring(str, f, Brush, r);
}
//方法二(此方法为GridView没有设置数据源绑定时,使用,一般使用此种方法)
if (this._flag)
{
if (unt == 0)
{
string str = "没有查询到你所想要的数据!";
Font f = newFont("宋体", 10, FontS);
Rectangle r = newRectangle( + 5, + 5, -
5, t - 5);
tring(str, f, Brush, r);
}
}
}
9、如何显示水平滚动条?
设置thinsVienAutoWidth = false;
10、如何定位到第一条数据/记录?
设置irst()
11、如何定位到下一条数据/记录?
设置ext()
12、如何定位到最后一条数据/记录?
设置ast()
13、设置成一次选择一行,并且不能被编辑
RectStyle =
DevExpress.XtraG.ocusRectStcus;
nsBehavior.Editable = false;
nsSelectioeAppearanceFocusedCell = false;
14、如何显示行号?
atorWidth = 40;
//显示行的序号
privatevoid gridView1_CustomDrawRowIndicator(object sender, RowIndicatorCustomDrawEventArgs e)
{
if (Indicator && ndle>=0)
{
ayText = (ndle + 1).ToString();
}
}
15、如何让各列头禁止移动?
设置gridViewnsCustomization.AllowColumnMoving = false;
16、如何让各列头禁止排序?
设置gridViewnsCustomization.AllowSort = false;
17、如何禁止各列头改变列宽?
设置gridViewnsCustomization.AllowColumnResizing = false;
18、
19、
20、
21、
22、
23、
24、
25、
26、
三、navBarControl
1、如何在每一个navBarGroup里添加自己想要的控件
设置GroupStyle:ControlContainer
2、如何设置navBarGroup有滚动条
设置SkinExplorerBarViewScrollStyle:ScrollBar
3、 如休把navBarGroup设置成如下样式
如图所示:
设置navBarGroup的PaintStyleName属性为SkinN:avigationPane
四、toolTipController
效果图如下:
1、如何设置显示的时间长短
设置thiipControllopDelay = 2000;
2、如何在屏幕上显示如上图所示的效果
ToolTipControllerShowEventArgs args = ipControlleShowArgs();
ipControllolTip(es, "请选择一条记录!");
ipControlltle(es, "提示");
ipControllolTipIconType(es,
DevExpress.Utils.ToolTipIconType.Exclamation);
ipControlleak = true;
ipControllhadow = true;
ipControlled = true;
ipControllint("请选择一条记录!", "提示");
ip = "请选择一条记录!";
= "提示";
3、如何设置边框的颜色
ipControllrance.BorderColor = Color.Red;
五、TextEdit
1、如何设置TextEdit为多行,可拉伸
设置TextEdit的Propertity->AutoHeight为:False
六、LayoutControl
1、如何设置LayoutItem为隐藏
设置LayoutItility = Never
七、TreeList
1、如何隐藏TreeList的列头
设置TreeListr的OptionsView的ShowColumns属性为:False
2、如何
八、PictureEdit
1、如何禁止PictureEdit的右键菜单?
设置PictureEdit的Properties->ShowMenu为:false
九、TreeList
1、 如何让TreeList的每个结点高亮显示?
效果如下:
代码如下:
privatevoid treeList1_CustomDrawNodeCell(object sender,
DevExpress.XtraTreeLimDrawNodeCellEventArgs e)
{
TreeList node = sender asTreeList;
if ( == edNode)
{
ectangle(SystemBrusw, s);
Rectangle r = newRectangle(iewInntRec,
iewInntRec,
Conve32(reString(ext, treeL).Width
+ 1),
Conve32(reString(ext,treeL).Height));
ectangle(SystemBrusight, r);
tring(ext, treeL, SystemBrusightText, r);
ed = true;
}
}
//============================================================================
//===============================以下内容为收集===============================
//============================================================================
一、改变grid的样式。
DevExpress.XtraGarances xapp;
xapp=newDevExpress.XtraGarances(SysteonmenlderPath(SysteonmenalFolm) + "DevExpress.XtraGrance ");
cheme(“样式名字”, gridControiew);
二、选择单元设置和取所选的值
gridVnsSelectioSelectMode=GridMultiSelectelect;
gridVnsSelectioSelectMode=GridMultiSelectlect;//
gridVnsSelectioSelect = ceMultiSeled; //多行选择
三、gridview的控制
///<取当前选中的值>
string GetSelectedRows(GridView view) {
string ret = "";
int rowIndex = -1;
if(nsSelectioSelectMode == GridMultiSelectlect) {
foreach(int i in gridVlectedRows()) {
DataRow row = gridVtaRow(i);
if(ret != "") ret += "rn";
ret += strint("Company Name: {0} (#{1})", row["CompanyName"], i);
}
}
else {
foreach(GridCell cell in lectedCells()) {
if(rowIndex != ndle) {
if(ret != "") ret += "rn";
ret += strint("Row: #{0}", ndle);
}
ret += "rn " + wCellDisplayText(ndle,
n);
rowIndex = ndle;
}
}
return ret;
}
///<设置选中的颜色>//半透明的效果
privatevoid icbTranslucentColors_CheckedChanged(object sender, SysteArgs e) {
if(icbTranslucentColors.Checked) {
gridVrance.SelectedRoolor = Color.FromArgb(30, 0, 0, 240);
gridVrance.FocusedRow.BackColor = Color.FromArgb(60, 0, 0, 240);
}
else {
gridVrance.SelectedRo();
gridVrance.FocusedRow.Reset();
}
}
///<自动添加一行>
gridVnsVieemRowPosition = NewItemRowPositm//Top/None;
///<设置gridView的按钮>
gridVuttonMode = ShowButtonModeEnum.。。。。。。
gridVnsBehavior.Editable = chEdied; //设置按钮是否可用
///向选中的空间输入字符串
SendK(“fsfds”);
///控件焦点
gridContro();
四、cardView的设置
///是否现实快捷按钮CustomizeButton
cardVnsVieuickCustomizeButton=true/false;
///设置CustomizeButton的能否排序和过滤
foreach(GridColumn col in cardVns)
{ nsColSort}
foreach(GridColumn col in cardVns)
{ nsFilFilter}
///card的头上的ico显示
cardVtChanged();
///card的头上的标题改变显示
cardVaptionFormat =””;
///cardview显示的单个记录的折叠按钮
cardVnsVieardExpandButton=true;
///
cardVumCardColumns =iSize
cardVumCardRows = val;
cardVnsBehavior.AutoHorzWidth
///多选
cardVnsSelectioSelect = ceMultiSeled;
foreach(int i in cardVlectedRows()) {
DataRow row = cardVtaRow(i);
if(ret != "") ret += "rn";
ret += strint("{0} / {1} : {2:$#,0.00}", row["Trademark"], row["Model"],
row["Price"]);
}///查看选择中的记录
CellMerging(单元格合并的效果)
///
CellMerging(单元格合并的效果)
gridVnsVieCellMerge = ceMered;
Fixed Bands(bandedGridView)
///两边固定
gridBand3 的一列的Fixed属性改成 Right,Left,None
///固定与非固定列之间的距离用
bandedGridView2.FixedLineWidth = (int)numFixedLineWid;
///设置列的颜色
打开Run Designer 选中Columns 选中要改变的列 里面有AppearanceCell (设置列的外观)和 AppearanceHeader(设置表格头的外观)
或者选中该列查看“属性”里面也有这两个属性。
///统计(gridView bandedGridView通用)
分组统计和全部统计:
全部统计:在最下面显示统计的结果。
Run Designer->Total Summary //->General 设置显示
//->Columns 对特定列来设置统计
汇总结果是否显示:可以通过gridControl的view的ShowFooter属性来设置表格下面的汇总结果
分组统计:
以上就是“分组”的 显示在每个分组下面来显示汇总结果。
通过bandedGridVieFooterShowMode=GroupFooterShowMode.。。。。设置分组的显示模式。
///GridView设置菜单
#region Grid events
privatevoid gridView1_ShowGridMenu(object sender,
DevExpress.XtraG.enuEventArgs e) {
if(ype == DevExpress.XtraG.enuTyn) {
DevExpress.XtraGiewColumnMenu menu = as
DevExpress.XtraGiewColumnMenu;
.Clear();
if(n != null) {
.Add(CreateCheckItem("Not
.Add(CreateCheckItem("Fixed
Fixed",
Left",
n,
n,
FixedStyle.None, imageList2.Images[0]));
FixedStyle.Left, imageList2.Images[1]));
}
#endregion
#region New column menu
DXMenuCheckItem CreateCheckItem(string caption, GridColumn column, FixedStyle style,
}
}
.Add(CreateCheckItem("Fixed Right", n,
FixedStyle.Right, imageList2.Images[2]));
Image image) {
DXMenuCheckItem item = newDXMenuCheckItem(caption, colum == style, image,
newEventHandler(OnFixedClick));
}
void OnFixedClick(object sender, EventArgs e) {
}
classMenuInfo {
}
public MenuInfo(GridColumn column, FixedStyle style) {
}
publicFixedStyle Style;
publicGridColumn Column;
n = column;
= style;
DXMenuItem item = sender asDXMenuItem;
MenuInfo info = asMenuInfo;
if(info == null) return;
= ;
= newMenuInfo(column, style);
return item;
#endregion
///gridview cardView自动行高
行高自动匹配
gridVnsVietoHeight = ed;
cardVnsBehavior.FieldAutoHeight = ed;
当文字多的时候(行高自动匹配设置是才有用)
repositoryItemMemoEdCount = ed ? 0 : 1;
设置自动全部显示该的所有行。
///BandedGridView自己订制列的方法
advBandedGridVinsCustomization();
advBandedGridVioyCustomization();
advBandedGridVinsCustomization.AllowChangeColumnParent = ed;
advBandedGridVinsCustomization.AllowChangeBandParent = ed;
advBandedGridVinsCustomization.ShowBandsInCustomizationForm = ed;
///设置 图片动画模式
gridVnsVietionType = (GridAnimationType)
///根据字段来分组模式
switch(index) {
void SetInterval(GridColumn column, ColumnGroupInterval interval) {
columInterval = interval;
case 0:
SetInterval(gridColumn1, ColumnGroupIntebetical);
gridColumnInterval = ColumnGroupIntebetical;
break;
图片时(行高自动匹配设置是才有用)
repositoryItemPictureEditmHeight = ed ? 0 : 40;
case 1:
SetInterval(gridColumn5, ColumnGroupInteonth);
break;
SetInterval(gridColumn5, ColumnGroupInteear);
break;
case 2:
case 3:
SetInterval(gridColumn5, ColumnGroupInteange);
break;
case 4:
SetSortMode(gridColumn4, ColumnSortm);
break;
SetInterval(gridColumn2, ColumnGroupInte);
break;
}
default:
}
columIndex = 0;
void SetSortMode(GridColumn column, ColumnSortMode sortMode) {
}
columode = sortMode;
columIndex = 0;
改变分组样式
gridVnsVieDrawMode = (GroupDrawMode)
///清除分组
gridVGrouping();
foreach(GridColumn column in gridVns) {
columInterval = ColumnGroupIntelt;
columode = ColumnSortlt;
}
///CustomDataSummaries设置Grop
privatevoid numCustom_ValueChanged(object sender, SysteArgs e) {
CustomGrideSummary();
UpdateCaptions(numCu);
}
privatevoid UpdateCaptions(decimal d) {
CustomGridSummary[0].DisplayFormat = "(Order Count [WHERE Freight >= " +
ing() + "] = {0})";
OnSetCaption("");
gridVtConditions[0].Value1 = d;
}
protectedoverridevoid OnSetCaption(string fCaption) {
fCaption = "count records WHERE Freight >= " + numCu.ToString();
if(Caption != null)
Capti = strint("{0} ({1})", TutorialName, fCaption);
}
///下面的效果的实现
Run Designere -> Style Conditions ->Add ->column设置列的 Condition设置条件
value1,value2是参数值
代码:
publicvoid setStyle(GridView gridView)
{
StyleFormatCondition cn;
cn = newStyleFormatCondition(FormatCondition, gridVns["bd_c"],
null,false);
ToRow = true;//false只对列其作用。
rance.Font = newFont(AppearanceObjecltFont, FontS);
rance.ForeColor = Color.Brown;
gridVtCondition(cn);
}
///LayoutView
layoutViewnsCarouselAngle = (float)(((int)flatFactor.EditValue) / 360.0f * 2
* );///卡片的高度设置flatFactalue的值(0-360)
layoutViewnsCarouselngle = (float)(((int)rollAalue) / 360.0f * 2 *
);/////卡片的旋转角度设置rollAnalue的值(0-360)
layoutViewnsCarouselmCardScale = ((int)endSizeScaalue) / 100.0f;
///卡片的距离设置endSizeSalue的值(0-100)
layoutViewnsCarouselmCardAlphaLevel = ((int)endAlalue) / 100.0f;
///卡片的卡片透明程度设置endAalue的值(0-100)
layoutViewnsCarouselmCardFading = ((int)bottomCardFadinalue) /
100.0f;///卡片的卡片褪色程度设置bottomCardFadialue的值(0-100)
layoutViewnsCarouselount = (int)cardsCount.EditValue;
///卡片的能显示数量设置cardsCount.EditValue的值(0-20)
layoutViewnsCarouselpolationMode = (InterpolationMode)
//修改卡片的方式
///layout卡片的样式在 run designer -> layout里面设置
Size originalCardMinSize = ;
privatevoid zoomTrackBarControl1_EditValueChanged(object sender, EventArgs e) {
if(originalCardMinSize == ) originalCardMinSize = layoutViewinSize;
double koeff = ((int)zoomTrackBarControl1.EditValue) / 100.0 - 0.2;
Size newSize = newSize(originalCardMin + (int)(originalCardMin * koeff),
originalCardMint + (int)(originalCardMint * koeff));
layoutViewinSize = newSize;
}////设置卡片的大小的(zoomTrackBarControl1z(0-100))
下图中设置layoutView位置的方法
protectedvoid SetMasterTableLeftPlacement() {
LayoutItemDragController dc = newLayoutItemDragController(masterTableItem, detailTableItem,
InsertLocae, LayoutType.Horizontal);
DoDragItem(dc);
SetMasterViewColumnLayout();
}
protectedvoid SetMasterTableRightPlacement() {
LayoutItemDragController dc = newLayoutItemDragController(masterTableItem, detailTableItem,
InsertLoca, LayoutType.Horizontal);
DoDragItem(dc);
SetMasterViewColumnLayout();
}
privatevoid SetMasterTableTopPlacement() {
LayoutItemDragController dc = newLayoutItemDragController(masterTableItem, detailTableItem,
InsertLocae, LayoutType.Vertical);
DoDragItem(dc);
SetMasterViewRowLayout();
}
protectedvoid SetMasterTableBottomPlacement() {
LayoutItemDragController dc = newLayoutItemDragController(masterTableItem, detailTableItem,
InsertLoca, LayoutType.Vertical);
DoDragItem(dc);
SetMasterViewRowLayout();
}
protectedvoid DoDragItem(LayoutItemDragController dc) {
masterTableItem.SizeConstraintsType =
DevExpress.XtraLayout.SizeConstraintslt;
masterTableItem.Move(dc);
}
protectedvoid SetMasterViewColumnLayout() {
SetMasterItemVerticalSize();
employesLayoutVnsBehavior.AllowSwitchViewModes = true;
employesLayoutVnsVieode = LayoutViewn;
employesLayoutVnsBehavior.AllowSwitchViewModes = false;
employesLayoutVsh();
}
protectedvoid SetMasterViewRowLayout() {
SetMasterItemHorizontalSize();
employesLayoutVnsBehavior.AllowSwitchViewModes = true;
employesLayoutVnsVieode = LayoutView;
employesLayoutVnsBehavior.AllowSwitchViewModes = false;
employesLayoutVsh();
}////private DevExpress.XtraLayout.LayoutControlItem masterTableItem;
///直接打印gridcontrol
Cursor currentCursor = Cursont;
Cursont = Cursoursor; //取当前的鼠标。并设置
if(DevExpress.XtraPrintiHelpentingAvailable)
DevExpress.XtraPrintiHelpereview(gridControl1);///打印
else
MessageBox.Show("XtraPrinting Library is not found...", "Information", MessageBoxButto,
MessageBoxmation);
Cursont = currentCursor;
版权声明:本文标题:DevExpress-GridView使用大全 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.freenas.com.cn/free/1702860313h433592.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论