Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
955
Why the row was not removed successfully from the ultragrid?
posted

When the WinForm is loaded, there is nine pieces of records in the ultragrid. then I click the ultraButton1 to delete the second data row, and it displays eight  pieces of records
in the ultragrid right now, but I click ultraButton2, the MessagBox show  nine pieces of records, and run the code this.Text=m_dt.Rows[1]["UnitCode"], throw an error(System.Data.DeletedRowInaccessibleException).
Now how to let the deleted row is removed from this.ultraGrid1.DataSource  when I execute m_dt = (DataTable)this.ultraGrid1.DataSource?

All the codes as below:

        private void Form1_Load(object sender, EventArgs e)
        {
            SqlExecuteMaster SqlOP = new SqlExecuteMaster();
            DataTable dt = new DataTable();
            string strSql = "Select UnitCode,UnitName,remark from Pb_unit";
            dt = SqlOP.GetDataTable(strSql);// generate datatable
            this.ultraGrid1.DataSource = dt;
        }

        private void ultraButton1_Click(object sender, EventArgs e)
        {
            this.ultraGrid1.Rows[1].Delete(false);
            this.ultraGrid1.Refresh();
        }


        private void ultraButton2_Click(object sender, EventArgs e)
        {
            DataTable m_dt = new DataTable();
            m_dt = (DataTable)this.ultraGrid1.DataSource;
            MessageBox.Show(m_dt.Rows.Count.ToString());
            this.Text=m_dt.Rows[1]["UnitCode"];
        }
 

Parents
  • 469350
    Verified Answer
    Offline posted

    This is simply the way DataTables work. The DataTable just marks the row as deleted, but keeps it around so that it has a record of the row and can delete it from the database later. I'm pretty sure there are methods on the DataTable to get only the rows that are currently not deleted. There's also a state property on the DataRow.

Reply Children
No Data