• winform界面笔记


    DataGridView

    目标:实现如下类似效果

    核心代码:

                dataGridView1.Rows[row].Cells[col].Style.Padding =
                    new Padding(dataGridView1.Rows[row].Cells[col].OwningColumn.Width, 0, 0, 0);
                dataGridView1.Rows[row].Cells[col].Style.BackColor = Color.Gray;

     一个完整的实例:

     参考https://stackoverflow.com/questions/14124033/hide-some-datagridview-checkbox-cell

    代码

    namespace TestDGV
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void AddRow_Click(object sender, EventArgs e)
            {
                this.dataGridView1.Rows.Add();
            }
    
            private void AddColumn_Click(object sender, EventArgs e)
            {
                string colInfo = this.ColumnName.Text;
                if(string.IsNullOrEmpty(colInfo))
                {
                    MessageBox.Show("Column Info Empty.");
                    return;
                }
                if(dataGridView1.Columns.Contains(colInfo))
                {
                    MessageBox.Show("Column Name Exist.");
                    return;
                }
                var c = new DataGridViewTextBoxColumn();
                c.HeaderText = colInfo;
                c.Name = colInfo;
                dataGridView1.Columns.Add(c);
            }
    
            private void GreyCell_Click(object sender, EventArgs e)
            {
                int row;
                if(!Int32.TryParse(this.RowIndex.Text,out row))
                    return;
                int col;
                if (!Int32.TryParse(this.ColumnIndex.Text, out col))
                    return;
    
                if (row >= this.dataGridView1.Rows.Count)
                    return;
    
                if (col >= this.dataGridView1.Columns.Count)
                    return;
                dataGridView1.Rows[row].Cells[col].Style.Padding =
                    new Padding(dataGridView1.Rows[row].Cells[col].OwningColumn.Width, 0, 0, 0);
                dataGridView1.Rows[row].Cells[col].Style.BackColor = Color.Gray;
            }
        }
    }
    View Code
  • 相关阅读:
    Oracle 分析函数
    Oracle 增加修改删除字段
    Oracle 重置序列
    End2EndIT
    Hyperledger Fabric SDK use case 1
    云计算中8项核心技术
    Cloud
    JVM Guide
    微信公众平台PHP开发
    在Linux系统环境下修改MySQL的root密码
  • 原文地址:https://www.cnblogs.com/noigel/p/14153983.html
Copyright © 2020-2023  润新知