zoukankan      html  css  js  c++  java
  • datagridView的数据列绑定问题

    单元格格式化数据
    private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
    {
       
    if (e.ColumnIndex == 1 /*status列的Index*/)
        {
           
    if (object.Equals(e.Value, 0))
            {
                e.Value
    = "未完成";
                e.CellStyle.ForeColor
    = Color.Red;
            }
           
    else
            {
                e.Value
    = "已完成";
                e.CellStyle.ForeColor
    = Color.Green;
            }
        }
    }

     

    行数据格式化数据,一行的单元格数据可以根据另一个单元值而定

     

    private void dataGridView1_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
            {

                    int rowsindex=e.RowIndex ;
                    int row_count=dataGridView1 .Rows.Count ;
                    if (rowsindex < row_count - 1)
                    {

                        DataGridViewRow dgr = dataGridView1.Rows[e.RowIndex];
                        try
                        {
                            dgr.Cells["name_values"].Value = dgr.Cells["Column0"].Value.ToString();
                            //dgr.DefaultCellStyle.ForeColor = 设置的颜色;                       
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                    }


            }

     

     

  • 相关阅读:
    acwing272. 最长公共上升子序列
    哈夫曼编码简单实现
    Linked List Sorting
    jmeter-线程组
    css-书写规范
    mysql-踩坑记录
    vue-npm install
    css-选择器
    js-process对象
    linux-常用命令
  • 原文地址:https://www.cnblogs.com/xiaofengfeng/p/2013869.html
Copyright © 2011-2022 走看看