DataGridView控件相关使用总结

1. 给DataGridView表格前面添加序号

        //设置DataGridView表格前面的序号
        private void ProDataView_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            SolidBrush sbrush = new SolidBrush(Color.Black);
            e.Graphics.DrawString((e.RowIndex + 1).ToString(), 
                                  e.InheritedRowStyle.Font, 
                                  sbrush, 
                                  e.RowBounds.Location.X + 10, 
                                  e.RowBounds.Location.Y + 5);
        }

2. 在线程中访问DataGridView

//设置DataGridView表格的数据源
        private void SetDataGridViewSource(BindingSource bs)
        {
            if (this.ProDataView.InvokeRequired)
            {
                AddDataGridViewSource d = new AddDataGridViewSource(SetDataGridViewSource);
                this.ProDataView.Invoke(d, new object[] { bs });
            }
            else
            {
                this.ProDataView.DataSource = bs;                
            }
        }

3. 其他一些小的应用

//返回DataGridView表格的总行数
        private int ProDataView_GetRowCount()
        {
            return this.ProDataView.RowCount;
        }

        //返回DataGridVIew表格中的总列数
        private int ProDataView_GetColumnCount()
        {
            return this.ProDataView.ColumnCount;
        }

        //返回DataGridView表格中指定位置的数据
        private string ProDataView_GetCellDataText(int iRow, int iColumn)
        {
            return this.ProDataView.Rows[iRow].Cells[iColumn].Value.ToString();
        }



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值