this.dataGrid2.GetCellBounds(row, 0)
你要判断 是否 数据行

解决方案 »

  1.   

    int row = 0;
    int yDelta = dataGrid1.GetCellBounds(0, 0).Height + 1;
    int y = dataGrid1.GetCellBounds(0, 0).Top + 2; CurrencyManager cm = (CurrencyManager)this.BindingContext[dataGrid1.DataSource, dataGrid1.DataMember]; while (y < dataGrid1.Height - yDelta && row < cm.Count)//显示行索引
    {
    //get & draw the header text...
    string text = string.Format("{0}", row);
    e.Graphics.DrawString(text, dataGrid1.Font, new SolidBrush(Color.Black), 12, y);
    y += yDelta;
    row++;
    }
      

  2.   

    roselxy1981   你说的这样不可以啊!我试过了,还是没有序号列显示啊!  可以把完整的代码发给我吗?    
      

  3.   

    为什么不 用 
    foreach(DataRow dr in ds2.Tables[0].Rows)
    {}
    不明白搂住想做什么,
    要增加一列来做序号 这个序号做什么得 需不需要 在 datagrid里显示?
    不管需不需要显示。 这一列添加在 dataset的table中不是更便捷么?this.dataGrid2.GetCellBounds(row, 0).Y + 2出错的话 建议搂住打断点 调试 ,跟踪一下row的值。看看到底是执行到哪里出错了, 出错时 row是多少