zoukankan      html  css  js  c++  java
  • 看上去没有输入焦点的只读DataGrid (WinForm)

    假设已经在WinForm窗体上放置了一个名称为dataGridMsg的DataGrid,并且为窗体增加一个成员 
    private DataSet DataSetMsg; 
    在form的Load中添加以下代码 
    DataSetMsg 
    = new DataSet("DataSetMsg"); 
    DataTable dt
    = DataSetMsg.Tables.Add("DataTableMsg"); 
    dt.Columns.Add(
    "Code",typeof(string)); 
    dt.Columns.Add(
    "Msg",typeof(string)); 
    dt.Columns.Add(
    "V",typeof(string));//添加用于隐藏输入焦点的列 
    //添加10行 
    for(int B=0;B<10,B++

    DataRow dr 
    = new dt.NewRow(); 
    dr[
    "Code"= B.ToString().PadLeft(4,'0'); 
    dr[
    "Msg"= "Msg"+B.ToString(); 
    dr[
    "V"= ""
    }
     
    dataGridMsg.ReadOnly 
    = true
    //指定DataGridMsg列的外观 
    DataView dataviewMsg = new DataView(DataSetMsg.Tables["DataTableMsg"]); 
    dataviewMsg.AllowDelete 
    = false
    dataviewMsg.AllowNew 
    = false
    dataGridMsg.SetDataBinding(dataviewMsg,
    ""); 
    DataGridTableStyle ts1 
    = new DataGridTableStyle(false); 
    ts1.MappingName 
    = "DataTableMsg"
    ts1.AllowSorting 
    = true
    ts1.GridColumnStyles.Clear(); 
    //第0列--代码 
    DataGridTextBoxColumn CCode = new DataGridTextBoxColumn(); 
    CCode.MappingName 
    = "Code"
    CCode.HeaderText 
    = "代码"
    CCode.Width 
    = 100
    CCode.Alignment 
    = HorizontalAlignment.Center; 
    CCode.ReadOnly 
    = true
    ts1.GridColumnStyles.Add(CCode); 
    //第1列-- 信息 
    DataGridTextBoxColumn Cmsg = new DataGridTextBoxColumn(); 
    Cmsg.MappingName 
    = "Msg"
    Cmsg.HeaderText 
    = "信息"
    Cmsg.ReadOnly 
    = true
    Cmsg.Alignment 
    = HorizontalAlignment.Left; 
    Cmsg.Width 
    = 600
    ts1.GridColumnStyles.Add(Cmsg); 
    //第2列--用于隐藏输入焦点的列 
    DataGridTextBoxColumn CV = new DataGridTextBoxColumn(); 
    CV.MappingName 
    = "V"
    CV.ReadOnly 
    = true
    CV.Width 
    = 0;//隐藏的列 
    ts1.GridColumnStyles.Add(CV); 
    dataGridMsg.TableStyles.Clear(); 
    dataGridMsg.TableStyles.Add(ts1); 
    在 dataGridMsg的CurrentCellChanged 事件中添加以下代码 
    //将当前列始终设置为定义的隐藏列2 
    dataGridMsg.CurrentCell = new DataGridCell(dataGridMsg.CurrentCell.RowNumber,2); 
  • 相关阅读:
    97. Interleaving String
    96. Unique Binary Search Trees
    95. Unique Binary Search Trees II
    94. Binary Tree Inorder Traversal
    odoo many2many字段 指定打开的form视图
    docker sentry 配置文件位置
    postgres 计算时差
    postgres 字符操作补位,字符切割
    postgres判断字符串是否为时间,数字
    odoo fields_view_get
  • 原文地址:https://www.cnblogs.com/bearhb/p/207546.html
Copyright © 2011-2022 走看看