第一点可以参考这里的回答
http://expert.csdn.net/Expert/topic/1034/1034562.xml?temp=.2088434
第二点,一个解决的办法是写一个继承DataGridTextBoxColumn的类
public class DataGridEnableTextBoxColumn : DataGridTextBoxColumn
{
protected override void Edit(System.Windows.Forms.CurrencyManager source, int rowNum, System.Drawing.Rectangle bounds, bool readOnly, string instantText, bool cellIsVisible)
{
if (条件)//设定禁止编辑的条件
readOnly=true;
else
readOnly=false;
base.Edit(source, rowNum, bounds, readOnly, instantText, cellIsVisible);
}
}
在程序中使用这个类,示例:
private void Form1_Load(object sender, System.EventArgs e)
{
//qlConnection1连接SQL数据库NorthWind
SqlDataAdapter da=new SqlDataAdapter("select LastName,FirstName from employees",this.sqlConnection1);
DataSet ds=new DataSet();
da.Fill(ds,"employees");DataGridTableStyle ats=new DataGridTableStyle();
ats.MappingName="employees";
DataGridEnableTextBoxColumn dcs1=new DataGridEnableTextBoxColumn();
dcs1.HeaderText="lastname";
dcs1.MappingName="LastName";
ats.GridColumnStyles.Add(dcs1);

DataGridTextBoxColumn dcs2=new DataGridTextBoxColumn();
dcs2.HeaderText="firstname";
dcs2.MappingName="FirstName";
ats.GridColumnStyles.Add(dcs2);

this.dataGrid1.TableStyles.Add(ats);
this.dataGrid1.DataSource=ds;
this.dataGrid1.DataMember="employees";
}