日期:2014-05-17 浏览次数:20673 次
//如果希望DataGridView 内某个单元格不可编辑
//设置 DataGridView1 的第2列整列单元格为只读
DataGridView1.Columns[1].ReadOnly = true;
// 设置 DataGridView1 的第3行整行单元格为只读
DataGridView1.Rows[2].ReadOnly = true;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WinApp {
public partial class frmDatagridviewSample : Form {
public frmDatagridviewSample() {
InitializeComponent();
InitData();
}
private void InitData() {
System.Data.DataTable dt = new DataTable();
dt.Columns.Add("id");
dt.Columns.Add("name");
dt.Rows.Add(new object[] { 65, "a" });
dt.Rows.Add(new object[] { 66, "b" });
dt.Rows.Add(new object[] { 67, "c" });
dt.Rows.Add(new object[] { null, "c" });
dataGridView1.DataSource = dt;
dataGridView1.D