AutoSizeColumnsMode指定如何设置列宽
       setGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;


AutoSizeRowsMode指定如何设置行高
            setGridView.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;

 设定列标题的宽度可以自由调整
               setGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
设定行标题的宽度可以自由调整
                setGridView.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders;

               DataGridViewCheckBoxColumn column = new DataGridViewCheckBoxColumn();
               setGridView.Columns.Insert(0, column);

列标题文本居中   DataGridViewColumn控件中的列
                foreach (DataGridViewColumn col in setGridView.Columns)
                {
                    col.SortMode = DataGridViewColumnSortMode.NotSortable;
                }
                setGridView.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;


行高度   DataGridViewRow控件中的行
                foreach (DataGridViewRow rows in setGridView.Rows)
                {
                    rows.Height = 15;
                }


单击选取整行  SelectionMode指定如何设置单元格  DataGridViewSelectionMode可以如何选定单元格
                setGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; //FullRowSelect通过单击表头和所包含的单元格选取整行
设定不显示DateGridView的最左一列
                setGridView.RowHeadersVisible = false;

返回DataGridView控件中选中行的任意单元格的数据
            return setGridView.CurrentCell.OwningRow.Cells[0].Value.ToString();

posted on 2011-06-14 14:13  smiling face  阅读(1297)  评论(0编辑  收藏  举报