【C#】DataGridView操作

2021-06-27 22:06

阅读:505

标签:project   style   dtp   ade   oid   自定义背景   center   定义   绘制   

1、其一

            private const int ROW_HEIGHT = 70;
            private void setDataGridViewControl(int pageIndex, int pageSize)
            {
                pagePTR = pageSize * (pageIndex - 1);
                if (myRows != null)
                {
                    myDTProject.Rows.Clear();
                    for (int i = 0; i )
                    {
                        string myNO = myRows[pagePTR];
                        DataRow row = myDTProject.NewRow();
                        row[0] = myNO;
                        row[1] = myManageDB.getDataFromCell("proDepartment", "ProjectManager", "proNO", myNO);
                        row[2] = myRegexInfo.getMatchedChineseStr(myManageDB.getDataFromCell("proManager", "ProjectManager", "proNO", myNO));
                        row[3] = myRegexInfo.getMatchedChineseStr(myManageDB.getDataFromCell("proAuthor", "ProjectManager", "proNO", myNO));
                        row[4] = myManageDB.getDataFromCell("proEditDate", "ProjectManager", "proNO", myNO).Split( )[0];
                        row[5] = myManageDB.getDataFromCell("proName", "ProjectManager", "proNO", myNO);
                        myDTProject.Rows.Add(row);
                        pagePTR++;
                        if (pagePTR >= this.dgvPager.RecordCount)
                        {
                            break;
                        }
                    }

                    //用户不能调整列标题高度
                    dgvProjectManager.ColumnHeadersHeightSizeMode =
                        DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
                    //隐藏行标题
                    dgvProjectManager.RowHeadersVisible = false;
                    //设置行高
                    dgvProjectManager.RowTemplate.Height = ROW_HEIGHT;
                    //设置内边距大小
                    Padding newPadding = new Padding(0, 1, 0, ROW_HEIGHT - 35);
                    dgvProjectManager.RowTemplate.DefaultCellStyle.Padding = newPadding;
                    dgvProjectManager.AllowUserToAddRows = false;
                    dgvProjectManager.AllowUserToDeleteRows = false;
                    dgvProjectManager.AllowUserToResizeColumns = false;
                    //设置无单元格边框
                    dgvProjectManager.CellBorderStyle = DataGridViewCellBorderStyle.None;
                    //单元格选择模式为全选
                    dgvProjectManager.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
                    dgvProjectManager.MultiSelect = false;
                    dgvProjectManager.AutoResizeRows(DataGridViewAutoSizeRowsMode.AllCellsExceptHeaders);
                    //设置字体样式
                    dgvProjectManager.DefaultCellStyle.SelectionForeColor = Color.Black;
                    dgvProjectManager.DefaultCellStyle.ForeColor = Color.Black;
                    //设置选中行背景色,需要绘制自定义背景应该在RowPrePaint处理,并设置该属性为Color.Transparent;
                    //dataGridView.RowTemplate.DefaultCellStyle.SelectionBackColor = Color.LightSkyBlue;

                    dgvProjectManager.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
                    dgvProjectManager.DataSource = myDTProject;

                    //只需要把需要绘制的DataGridView传入DataGridViewRenderer即可,
                    //这里的隐藏列即为需要重新绘制的内容
                    DataGridViewRender render = new DataGridViewRender(dgvProjectManager,
                        dgvProjectManager.Columns[dgvProjectManager.ColumnCount - 1]);
                }
            }

 

【C#】DataGridView操作

标签:project   style   dtp   ade   oid   自定义背景   center   定义   绘制   

原文地址:https://www.cnblogs.com/haizhibin1989/p/10061711.html


评论


亲,登录后才可以留言!