码迷,mamicode.com
首页 > Windows程序 > 详细

【C#】DataGridView操作

时间:2018-12-03 23:32:29      阅读:381      评论:0      收藏:0      [点我收藏+]

标签: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 < dgvPager.PageSize; 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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!