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


            }

     

     

  • 相关阅读:
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    Spring框架——AOP面向切面编程
    Spring学习
    面试题整理
    Java Web前端到后台常用框架介绍
    【Oracle】SQL/92 执行多个表的连接
    什么是持久化?
  • 原文地址:https://www.cnblogs.com/xiaofengfeng/p/2013869.html
Copyright © 2011-2022 走看看