重载DataGridTextBoxColumn类可以做到
public class DataGridRightColumn:DataGridTextBoxColumn
{
protected override void Paint(Graphics g,Rectangle rc,CurrencyManager cm,int rowNumber,Brush backbrush,Brush forebrush,bool LtoR)
{
base.Paint(g,rc,cm,rowNumber,backbrush,forebrush,false);
}
}
private void Form1_Load(object sender, System.EventArgs e)
{
DataGridTableStyle ats=new DataGridTableStyle();
ats.MappingName="...";
DataGridRightColumn dcs1=new DataGridColorColumn();
dcs1.HeaderText="...";
dcs1.MappingName="...";
ats.GridColumnStyles.Add(dcs1);
...
this.dataGrid1.TableStyles.Add(ats);
}
public class DataGridRightColumn:DataGridTextBoxColumn
{
protected override void Paint(Graphics g,Rectangle rc,CurrencyManager cm,int rowNumber,Brush backbrush,Brush forebrush,bool LtoR)
{
base.Paint(g,rc,cm,rowNumber,backbrush,forebrush,false);
}
}
private void Form1_Load(object sender, System.EventArgs e)
{
DataGridTableStyle ats=new DataGridTableStyle();
ats.MappingName="...";
DataGridRightColumn dcs1=new DataGridColorColumn();
dcs1.HeaderText="...";
dcs1.MappingName="...";
ats.GridColumnStyles.Add(dcs1);
...
this.dataGrid1.TableStyles.Add(ats);
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货