1. 程式人生 > >C# dev SearchLookUpEdit 和 RepositoryItemSearchLookUpEdit 測試

C# dev SearchLookUpEdit 和 RepositoryItemSearchLookUpEdit 測試

goods pac tom true foo custom draw con sof

一、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, 35, NameSpacePath + "tb_Company");//配置下來表數據結構


   this.searchLookUpEditCus_no.Location = new System.Drawing.Point(54, 38);
            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(146, 20); this.searchLookUpEditCus_no.TabIndex = 5;

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

技術分享圖片

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 = 0; 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 = 100;
                    }
                    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 >= 0)
            {
                e.Info.DisplayText = (e.RowHandle + 1).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;//行背景顏色
        }

技術分享圖片

二、 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 = 1;
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 = 2;
SearchLookGridView.Columns.Add(ColPRD_NO);
//----------------------
GridColumn ColBARCODE = new GridColumn();
ColBARCODE.Tag = "BARCODE";
ColBARCODE.Name = "Col" + "BARCODE";
ColBARCODE.FieldName = "BARCODE";
ColBARCODE.Caption = "條形碼";
ColBARCODE.VisibleIndex = 3;
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 測試