DataGridView控件相关使用总结

来源:互联网 发布:python解压zip文件 编辑:程序博客网 时间:2024/04/28 00:21

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



原创粉丝点击