winform的程序我用SqlDataAdapter读取数据,然后通过datatable填充到datagrid里,当没有记录的时候,只要一点datagrid,就会自动关闭。提示“其他信息:无法从未绑定到 DataTable 的 DataGrid 中读取数据。”请问怎么解决?

解决方案 »

  1.   

    你的datagrid的click事件、mousedown或mouseup事件,对datagrid做什么处理了,是那里的问题
      

  2.   

    mouseup做过处理,为了解决选择框的问题
    那应该怎么改呢?this.dg_InfoLesson.MouseUp += new System.Windows.Forms.MouseEventHandler(this.DataGridMouseUp);private void DataGridMouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
    {
    if(this.dg_InfoLesson.CurrentCell.ColumnNumber != 0)
    {
    return;
    }
    if(this.dg_InfoLesson[Convert.ToInt32(this.dg_InfoLesson.CurrentCell.RowNumber),0].ToString() == "False")
    {
    this.dg_InfoLesson[Convert.ToInt32(this.dg_InfoLesson.CurrentCell.RowNumber),0] = true;
    }
    else if(this.dg_InfoLesson[Convert.ToInt32(this.dg_InfoLesson.CurrentCell.RowNumber),0].ToString() == "True")
    {
    this.dg_InfoLesson[Convert.ToInt32(this.dg_InfoLesson.CurrentCell.RowNumber),0] = false;
    }
    }
      

  3.   

    搞定了判断一下datagrid的数据源是不是为空就行了