C# dev SearchLookUpEdit 和 RepositoryItemSearchLookUpEdit 测试

一、searchLookUpEdit 绑定数据源

   DataTable DtCompany = new DataTable();//数据源表,自己写数据。
searchLookUpEditCus_no.Properties.DataSource = DtCompany;//绑定数据源
GridView gridViewCompany = searchLookUpEdit1View; //获取GridView对象,以配置表格样式
DataTable dtCompanystrc = help.GetDataTableField("tb_Company");//方法:GetDataTableField(),获取数据表:DtCompany的字段,和中文描述
new GridMethod().GetSetGridContrl(dtCompanystrc, gridViewCompany, , NameSpacePath + "tb_Company");//配置下来表数据结构

   this.searchLookUpEditCus_no.Location = new System.Drawing.Point(, );
this.searchLookUpEditCus_no.Name = "searchLookUpEditCus_no";
this.searchLookUpEditCus_no.Properties.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] {
new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)});
this.searchLookUpEditCus_no.Properties.DisplayMember = "CompanyName";
this.searchLookUpEditCus_no.Properties.ValueMember = "CompanyID";
this.searchLookUpEditCus_no.Properties.View = this.searchLookUpEdit1View;
this.searchLookUpEditCus_no.Size = new System.Drawing.Size(, );
this.searchLookUpEditCus_no.TabIndex = ;

DataTable dtCompanystrc 的数据库表结构
CREATE TABLE [dbo].[TableDetail]
(
[ISID] [int] NOT NULL,
[TableName] [varchar] (30) NOT NULL,
[FileNames] [varchar] (30) NOT NULL,
[FILETYPE] [varchar] (20) NULL,
[SFNULL] [varchar] (1) NULL,
[SFKEY] [varchar] (1) NULL,
[ISIdentity] [varchar] (1) NULL,
[LONG] [int] NULL,
[DEFAULTS] [nvarchar] (100) NULL,
[REM] [nvarchar] (50) NOT NULL,
[REMARK] [nvarchar] (500) NOT NULL,
[Name] [varchar] (50) NULL,
[type2] [varchar] (20) NULL,
[IsEdit] [varchar] (2) NULL CONSTRAINT [DF__TableDeta__IsEdi__4D555BD0] DEFAULT ('T')
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[TableDetail] ADD CONSTRAINT [PK__TableDet__5769799B438BFA74] PRIMARY KEY CLUSTERED ([TableName], [FileNames]) ON [PRIMARY]
GO

C# dev SearchLookUpEdit 和 RepositoryItemSearchLookUpEdit 测试

 GetSetGridContrl 方法的代码

        /// <summary>
/// GridContrl--GridView 的设置
/// </summary>
/// <param name="gridView1">gridView1</param>
/// <param name="IndicatorWidth">-1 列的宽度</param>
/// <param name="dt"> 绑定的数据源</param>
/// <param name="ColCaption">列标题</param>
public void GetSetGridContrl(DataTable dt, GridView gridView1, int IndicatorWidth, string NameSpacePath)
{
//设置列索引为-1的列宽
gridView1.IndicatorWidth = IndicatorWidth;
gridView1.OptionsView.ShowAutoFilterRow = true;
gridView1.OptionsView.ColumnAutoWidth = false;
//自动列宽,会出现横向滚动条
gridView1.OptionsView.ColumnAutoWidth = false;
//自动列宽
gridView1.BestFitColumns();
gridView1.Appearance.OddRow.BackColor = Color.PaleGoldenrod; // 设置奇数行颜色 // 默认也是白色 可以省略
gridView1.OptionsView.EnableAppearanceOddRow = true; // 使能 // 和和上面绑定 同时使用有效
gridView1.Appearance.EvenRow.BackColor = Color.WhiteSmoke; // 设置偶数行颜色
gridView1.OptionsView.EnableAppearanceEvenRow = true; // 使能 // 和和上面绑定 同时使用有效
gridView1.OptionsView.ShowGroupPanel = false;
string FileNames = "", REM = "", LONG = "", type2 = "";
try
{
for (int i = ; i < dt.Rows.Count; i++)
{
FileNames = dt.Rows[i]["FileNames"].ToString();
REM = dt.Rows[i]["REM"].ToString();
LONG = dt.Rows[i]["LONG"].ToString();
type2 = dt.Rows[i]["type2"].ToString(); DevExpress.XtraGrid.Columns.GridColumn Col1 = new DevExpress.XtraGrid.Columns.GridColumn();
try
{
Col1.Width = Convert.ToInt32(LONG);
}
catch (Exception ex)
{
Col1.Width = ;
}
Col1.Tag = FileNames;
Col1.Name = "Col" + FileNames;
Col1.FieldName = FileNames;
Col1.Caption = REM; if (type2 == "时间")
{
Col1.DisplayFormat.FormatType = FormatType.DateTime;
Col1.DisplayFormat.FormatString = "yyyy-MM-dd HH:mm:ss"; }
if (type2 == "数值")
{
Col1.DisplayFormat.FormatString = "N4";
Col1.DisplayFormat.FormatType = FormatType.Numeric;
}
Col1.VisibleIndex = i;
gridView1.Columns.Add(Col1);
}
}
catch (Exception)
{ } //添加 行索引事件
gridView1.CustomDrawRowIndicator += gridView1_CustomDrawRowIndicator;
//布局变化时产生事件
gridView1.Layout += gridView1_Layout;
string xmlfile = path + NameSpacePath.Replace(".", "") + gridView1.Name + ".xml";
gridView1.Tag = xmlfile;
LoadLayout(gridView1);//加载窗格
gridView1.OptionsView.ShowFooter = true;
gridView1.RowStyle += gridView1_RowStyle;
}
        //首列行索引 和 不带百分号的模糊查询 设置
public static void gridView1_CustomDrawRowIndicator(object sender, RowIndicatorCustomDrawEventArgs e)
{
GridView gridView1 = (GridView)sender;
//设置行索引:列索引等于-1处设置行索引。
if (e.Info.IsRowIndicator && e.RowHandle >= )
{
e.Info.DisplayText = (e.RowHandle + ).ToString();
}
//设置筛选行不用输入百分号直接筛选
foreach (DevExpress.XtraGrid.Columns.GridColumn item in gridView1.Columns)
{
item.OptionsFilter.AutoFilterCondition = DevExpress.XtraGrid.Columns.AutoFilterCondition.Contains; //筛选条件设置为包含
} }
        /// <summary>
/// 布局变化时产生事件
///保存表格布局
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void gridView1_Layout(object sender, EventArgs e)
{
GridView gridView1 = (GridView)sender;
SaveLayout(gridView1);//布局变化时 自动保存窗格布局
}
///选中行的颜色和背景设置
public void gridView1_RowStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs e)
{
GridView gridView1 = (GridView)sender;
gridView1.Appearance.FocusedRow.ForeColor = Color.Red;//字体颜色
gridView1.Appearance.FocusedRow.BackColor = Color.Linen;//行背景颜色
}

C# dev SearchLookUpEdit 和 RepositoryItemSearchLookUpEdit 测试

二、  GridColumn-->RepositoryItemSearchLookUpEdit  --> gridView -->

public GridView SearchLookGridView = new GridView ();
SearchLookGridView 添加列
GridColumn ColPRDTYPE = new GridColumn();
ColPRDTYPE.Tag = "PRDTYPE";
ColPRDTYPE.Name = "Col" + "PRDTYPE";
ColPRDTYPE.FieldName = "PRDTYPE";
ColPRDTYPE.Caption = "类型";
ColPRDTYPE.VisibleIndex = ;
SearchLookGridView.Columns.Add(ColPRDTYPE);
//----------------------
GridColumn ColPRD_NO = new GridColumn();
ColPRD_NO.Tag = "PRD_NO";
ColPRD_NO.Name = "Col" + "PRD_NO";
ColPRD_NO.FieldName = "PRD_NO";
ColPRD_NO.Caption = "产品编号";
ColPRD_NO.VisibleIndex = ;
SearchLookGridView.Columns.Add(ColPRD_NO);
//----------------------
GridColumn ColBARCODE = new GridColumn();
ColBARCODE.Tag = "BARCODE";
ColBARCODE.Name = "Col" + "BARCODE";
ColBARCODE.FieldName = "BARCODE";
ColBARCODE.Caption = "条形码";
ColBARCODE.VisibleIndex = ;
SearchLookGridView.Columns.Add(ColBARCODE);
                        //GridContrl 创建一列
GridColumn gridColumnName = new GridColumn();
//创建对象 下拉 组件对象RepositoryItemSearchLookUpEdit
RepositoryItemSearchLookUpEdit repositoryItemSearchLookUpEdit1 = new RepositoryItemSearchLookUpEdit();
repositoryItemSearchLookUpEdit1.AutoHeight = false;
repositoryItemSearchLookUpEdit1.AutoHeight = false;
repositoryItemSearchLookUpEdit1.Buttons.AddRange(
new DevExpress.XtraEditors.Controls.EditorButton[] {
new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)
}
);
repositoryItemSearchLookUpEdit1.DisplayMember = "PRD_Name";//显示值
repositoryItemSearchLookUpEdit1.Name = "repositoryItemSearchLookUpEdit1";
repositoryItemSearchLookUpEdit1.ValueMember = "PRD_NO";//实际值
repositoryItemSearchLookUpEdit1.View = SearchLookGridView; //下拉框中的表格:Gridview对象
repositoryItemSearchLookUpEdit1.DataSource = DtGoods;//DtGoods数据源对象
//------------------------------------------------------
gridColumnName.Caption = REM;//标题
gridColumnName.ColumnEdit = repositoryItemSearchLookUpEdit1;//绑定下拉控件
gridColumnName.FieldName = FileNames;//设置数据源字段
gridColumnName.Name = "Col" + FileNames;//设置列Name属性
gridColumnName.Visible = true;
gridColumnName.VisibleIndex = i;
//-----------------------------------------------------
gridView1.Columns.Add(gridColumnName);

C# dev SearchLookUpEdit 和 RepositoryItemSearchLookUpEdit 测试

上一篇:[转载]SpringMVC的Model参数绑定方式


下一篇:蓝凌OA二次开发手册