• winform datagridview使用


    绑定datatable
    DataTable OrigDataDt;       
    OrigDataDt = this.dgOrigianlView.DataSource as DataTable;
    OrigDataDt = new DataTable();
    OrigDataDt.Columns.Add("Column1");
    dgOrigianlView.DataSource = OrigDataDt;
    
    DataRow dr = OrigDataDt.NewRow();
    dr[0]=Convert.ToString(pDeviceModel.DataVar1, 2);
    OrigDataDt.Rows.Add(dr);
    
    
    
     #region【方法:原始数据GRIDVIEW新增行事件响应方法】
     private void dgOrigianlView_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
    {
         try
       {
                    for (int i = 0; i < e.RowCount; i++)
                    {
                        dgOrigianlView.Rows[e.RowIndex + i].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight;
                        dgOrigianlView.Rows[e.RowIndex + i].HeaderCell.Value = (e.RowIndex + i + 1).ToString();
                    }
                    for (int i = e.RowIndex; i < dgOrigianlView.Rows.Count; i++)
                    {
                        dgOrigianlView.Rows[i].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight;
                        dgOrigianlView.Rows[i].HeaderCell.Value = (i + 1).ToString();
                    }
                }
                catch { }
             
            }
            #endregion
    
            #region【方法:原始数据GRIDVIEW删除行事件响应方法】
            private void dgOrigianlView_RowsRemoved(object sender, DataGridViewRowsRemovedEventArgs e)
            {
                try
                {
                    for (int i = 0; i < e.RowCount; i++)
                    {
                        dgOrigianlView.Rows[e.RowIndex + i].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight;
                        dgOrigianlView.Rows[e.RowIndex + i].HeaderCell.Value = (e.RowIndex + i + 1).ToString();
                    }
                    for (int i = e.RowIndex; i < dgOrigianlView.Rows.Count; i++)
                    {
                        dgOrigianlView.Rows[i].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight;
                        dgOrigianlView.Rows[i].HeaderCell.Value = (i + 1).ToString();
                    }
                }
                catch { }
               
            }
            #endregion
    
     #region【方法集合:列显示控制事件响应方法】
            private void ckbcolum1_CheckedChanged(object sender, EventArgs e)
            {
                if (ckbcolum1.Checked)
                {
                    this.dgDataView.Columns[0].Visible = false;
                }
                else
                {
                    this.dgDataView.Columns[0].Visible = true;
                }
    
            }
    
    
    
     //winform自动刷新功能
             int maxcount = this.dgDataView.Rows.Count;
                if (m_autorefresh)
                {
                    dgDataView.CurrentCell = dgDataView.Rows[maxcount - 2].Cells[2];
                }
    
    
          #region 【设置DATAGRID列颜色】
            private void SetDataViewColor()
            {
                dgDataView.Columns["FOrginalData1"].DefaultCellStyle.BackColor = Color.Aqua;
          }
    

      

  • 相关阅读:
    (第三周)c#程序理解
    (第三周)使用visual studio 2015进行单元测试
    (第二周)软件工程第二周之四则运算
    (第二周)读《我是一只IT小小鸟》有感
    Jmeter--参数化的两种方法
    接口测试(1)
    自动化测试框架Cucumber和RobotFramework的对比
    selenium2+Python--学习进阶路线图
    Robot Framework--环境搭建(Mac)
    Selenium2+Python--python3.6 安装 xlrd 模块---Mac
  • 原文地址:https://www.cnblogs.com/yanranziruo/p/10429952.html
Copyright © 2020-2023  润新知