我的问题是:
1。如何删除多行
2。如何更改单元硌内容和颜色
3。如何根据不同条件显示不同的底色和前景色
1。如何删除多行
2。如何更改单元硌内容和颜色
3。如何根据不同条件显示不同的底色和前景色
解决方案 »
- 关于C# IO问题,打开当前工作目录等等 求帮助!谢谢
- 怎么修改这个XML文件,在线求等
- NET的报表问题
- 不同Form之间方法的访问。
- 在下没分了,请教高人,vs.net2003中,使用AjaxPro.dll不成功的问题
- C#中 TreeView如下问题,该如何解决啊!!!
- windows程序出现错误:警告窗体的标题是Common Language Runtime Debugging Services
- 怎么我的可用分好几天都没加啦,有谁知道?
- 寻求:希望出版社出版--C#网络编程实例教程源代码
- C# 正则匹配<td rowspan="2">Movable Cone Diameter(mm)</td>中的 "Movable Cone Diamete" ?
- DataGridStyle问题
- 关于ListView中Column索引的问题
1。
public ArrayList GetSelectedRows(MyDataGrid dg)
{
ArrayList al = new ArrayList();
CurrencyManager cm1 = (CurrencyManager)this.BindingContext[dg.DataSource];
DataView dv = (DataView)cm1.List;
for(int i = 0; i < dv.Count; ++i)
{
if(dg.IsSelected(i))
al.Add(i);
}
return al;
}
以上返回选择项
-------------------------------------
下面是删除:
ArrayList ar=GetSelectedRows(dataGrid);
ar.Sort();
CurrencyManager cm = (CurrencyManager)this.BindingContext[dataGrid.DataSource];
for(int i=ar.Count-1;i>=0;i--)//一定得从选中行的最后一行开始删除,否则删除会出错的
{
cm.RemoveAt((int)ar[i]);
}
---------------------------------------------------------------------
2.设置单元格值:
dataGrid[eow,col]=123;
改变单元格颜色:
DataGridCell cl=new DataGridCell(r,c);
Graphics g=Graphics.FromHwnd(grd.Handle);
g.FillRectangle(new System.Drawing.SolidBrush(Color.YellowGreen),grd.GetCellBounds(cl));
g.DrawString(grd[r,c].ToString(), grd.Font, new System.Drawing.SolidBrush(Color.Blue),grd.GetCellBounds(cl));
3。在Paint事件中加入下面代码
int row=0;
int yDelta = dataGrid.GetCellBounds(row, 0).Height + 1;
int y =dataGrid.GetCellBounds(row, 0).Top + 2;
CurrencyManager cr = (CurrencyManager) this.BindingContext[dataGrid.DataSource,dataGrid.DataMember];
while(y <dataGrid.Height - yDelta && row < cr.Count)
{
DataView dv=(DataView)dataGrid.DataSource;
int v=int.Parse(dv[row]["age"].ToString());
if(v>40)//判断年龄大于40就改变颜色
{
for(int col=0;col<dataGrid.TableStyles[0].GridColumnStyles.Count;col++)
{
e.Graphics.FillRectangle(new System.Drawing.SolidBrush(Color.Snow),dataGrid.GetCellBounds(new DataGridCell(row, col)));
e.Graphics.DrawString(dataGrid[row, col].ToString(), dataGrid.Font, new System.Drawing.SolidBrush(Color.Red),dataGrid.GetCellBounds(new DataGridCell(row, col)));
}
}
y += yDelta;
row++;
}