winform DataGridView 通用初始化

Posted 陈德洲

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了winform DataGridView 通用初始化相关的知识,希望对你有一定的参考价值。

void DGV_Init()
        {

            //名称 类型 设备数 累计转发次数 累计转发数据数 状态
            for (int i = 0; i < 6; i++)
            {
                DataGridViewTextBoxColumn dc = new DataGridViewTextBoxColumn();

                dc.DataPropertyName = "FID";
                dc.SortMode = DataGridViewColumnSortMode.NotSortable;
                DGV_DetailsViewer.Columns.Add(dc);
            }
            
            DGV_DetailsViewer.Columns[0].Name = "Name";
            DGV_DetailsViewer.Columns[1].Name = "Type";
            DGV_DetailsViewer.Columns[2].Name = "DevNUM";
            DGV_DetailsViewer.Columns[3].Name = "TotalCnt";
            DGV_DetailsViewer.Columns[4].Name = "TotalDataCnt";
            DGV_DetailsViewer.Columns[5].Name = "State";

            DGV_DetailsViewer.Columns[0].HeaderText = "实例名称";
            DGV_DetailsViewer.Columns[1].HeaderText = "实例类型";
            DGV_DetailsViewer.Columns[2].HeaderText = "转发设备数";
            DGV_DetailsViewer.Columns[3].HeaderText = "累计转发次数";
            DGV_DetailsViewer.Columns[4].HeaderText = "累计转发数据";
            DGV_DetailsViewer.Columns[5].HeaderText = "是否启用";

            DGV_DetailsViewer.Columns[0].ReadOnly = true;
            DGV_DetailsViewer.Columns[1].ReadOnly = true;
            DGV_DetailsViewer.Columns[2].ReadOnly = true;
            DGV_DetailsViewer.Columns[3].ReadOnly = true;
            DGV_DetailsViewer.Columns[4].ReadOnly = true;

            DGV_DetailsViewer.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;

            DGV_DetailsViewer.AllowUserToResizeColumns = false;
            DGV_DetailsViewer.AllowUserToResizeRows = false;

        }

 

以上是关于winform DataGridView 通用初始化的主要内容,如果未能解决你的问题,请参考以下文章

Winform开发

C# winform panel 画笔初始化问题

winform datagridview 嵌套

c# winform datagridview界面上的行删了,但datagridview数据源没有同步如何解决

winform datagridview怎么选中多行

刷新 DataGridView 内容