zoukankan      html  css  js  c++  java
  • C# WinfForm 控件之dev表格 GridControl

    基本用法

    1.新建一个winformAPP 放一个gridControl 为gridC 再放一个button 用法与dataGrid一样

    代码如下:

            /// <summary>
            /// 显示数据
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void button1_Click(object sender, EventArgs e)
            {
                using (SqlConnection con = new SqlConnection("server=.;uid=sa;pwd=123;database=test"))
                {
                    using (SqlDataAdapter ada = new SqlDataAdapter("select * from users ", con))
                    {
                        DataTable dt = new DataTable();
                        ada.Fill(dt);
    
                        grdC.DataSource = dt;
                    }
                }
            }
    View Code

     2.取选中行标

    GridView.FocusedRowHandle

    3.不可编辑

    gridview -->OptionsBehavior -->Editable=false

    4.主从表(重点是 dataset 里有两个可以关联的表  建立两表的联系  再给dataset)

     string str = @"SELECT VPG.CustomerCode AS 客户编码, cus.CustomerName AS 客户名称, VPG.ProtectionGroupName AS 保护机组,  
                          VPG.ConfiguredRpoSenconds RPO秒,  VPG.Status AS 状态, VPG.VmsCount AS 虚拟机数量, VPG.Priority AS 优先级, 
                          VPG.ProvisionedStorageInMB AS 总空间, VPG.UsedStorageInMB AS 已用空间,ProtectionGroupId
                   FROM  dbo.Tbl_UDC_ProtectionGroupStatus AS VPG LEFT OUTER JOIN
                         dbo.Tbl_UDC_CustomerList AS cus ON VPG.CustomerCode = cus.CustomerCode where 1=1 ";
                          //VPG.ActualRPO, VPG.ActualRTO, VPG.ProtectionGroupId, VPG.SiteId 这几个可能没有用
    
                if (this.CusCode != "")
                    str = str + string.Format(" and VPG.customerCode = '{0}'", this.CusCode);
    
                str = str + @" select VmName VM名称,Status 状态,Priority 优先级,ProvisionedStorageInMB 总容量 ,JournalUsedStorageMb 已用空间,VpgId,CustomerCode  from Tbl_UDC_VmResourceInfo";
    
                DataSet dsMD = dh.GetDataSet(str);
               
    
                DataRelation relation = new DataRelation("VPG", dsMD.Tables[0].Columns["ProtectionGroupId"], dsMD.Tables[1].Columns["VpgId"]);
                dsMD.Relations.Add(relation);
    
                gcVPG.DataSource = dsMD.Tables[0];
    View Code

    5.样式

    gridControl-->LookAndFeel-->UsedDefaultLookAndFree=false-->skinName(改下下就可以了)

    6.动态创建 GridControl 读取数据 并第一列设定记录行数

    GridControl grid = new GridControl();
                GridView gv = new GridView();
                gv.OptionsView.ShowFooter = true;
                gv.OptionsView.ShowGroupPanel = false;
                gv.OptionsView.ColumnAutoWidth = false;
                grid.MainView = gv;
                grid.Dock = DockStyle.Fill;
    
                this.Controls.Add(grid);
    
    
                using (SqlConnection con = new SqlConnection("server=.;uid=sa;pwd=123;database=test"))
                {
                    using (SqlDataAdapter adp = new SqlDataAdapter("select * from tbl_test ", con))
                    {
                        DataTable dt = new DataTable();
                        adp.Fill(dt);
    
                        grid.DataSource = dt;
                    }
    
                }
    
                gv.Columns[0].SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Count;
    View Code
  • 相关阅读:
    成功的两大法宝:自我管理与积累人脉
    CEO十五条法则 (是基于对CEO更加的关怀)
    百度李彦宏教你创业七大招!非常实用
    商业领袖摘下"帽子"才能炼成极致
    Alter index coalesce VS shrink space
    sort_area_size参数的一些表现
    Difference between parameter COMPATIBLE and OPTIMIZER_FEATURES_ENABLE
    Oracle常用的几个父栓
    Know more about RAC GES STATISTICS
    ORA07445 [SIGBUS] [Object specific hardware error]错误一例
  • 原文地址:https://www.cnblogs.com/SoftWareIe/p/8808209.html
Copyright © 2011-2022 走看看