现用dataGrid,通过dataSet显示数据库内容,但显示顺序和数据库表中不一致,请问为什么?
另外点击显示的列名如"学号",则dataGrid会按学号重新排序,这样在按dataGrid当前的行号更改数据就不是实际显示的该行的数据.例如重新排序后选中学号'2001',但进行修改时显示的信息可能是'2003'.请问如何解决,或是如何才能去掉DataGrid的自动排序功能.

解决方案 »

  1.   

    可以在你的数据库语句后添加order by 字段名 desc(或asc),desc是降序,asc是升序
    然后把dg的allowsorting 属性设置为false
      

  2.   

    BindingManagerBase bm = this.dataGrid.BindingContext[this.dataGrid.DataSource];
    bm.Position = dataGrid.CurrentCell.RowNumber;
    DataRow dr = ((DataRowView)bm.Current).Row;br即为选中的那一行
      

  3.   

    DateTime.Now.AddDays(-1).ToLongDateString()
      

  4.   

    使用DateDiff ,具体参数位置有点忘了DateDiff('d',now,1)
      

  5.   

    寒一个,我写的是sql的,c#的看楼上几位