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);
                        }
                    }


            }

     

     

  • 相关阅读:
    TabControl 切换 内嵌web页面直接响应滚动事件
    进程、应用程序域和对象上下文
    CSharp中的多线程——线程同步基础
    CSharp中的多线程——入门
    注重实效的程序员之快速参考指南
    学习语言技术快速入门——五步骤
    利用jQuery选择将被操作的元素
    CSharp中的多线程——使用多线程
    android开发文件介绍
    三角函数公式
  • 原文地址:https://www.cnblogs.com/xiaofengfeng/p/2013869.html
Copyright © 2011-2022 走看看