Bug: Datatable-bound Gridviews stuck in Read-Only when there is a UNION in the query

3 posts, 1 answers
  1. Philippe
    Philippe avatar
    25 posts
    Member since:
    Apr 2012

    Posted 05 Dec 2012 Link to this post

    Hello

    I created a new form, added a RadGridView to it, and populated it using a query containing a UNION statement.

    pGrid.BeginUpdate();
    // QueryDB below returns a Datatable with the resultset or the SELECT
    DataTable rs = clsDBConn.QueryDB("SELECT a,b,c FROM T1 UNION SELECT a,b,c FROM T2");
    pGrid.DataSource = null;
    pGrid.DataSource = rs;
    pGrid.MasterTemplate.AutoGenerateColumns = true;
    pGrid.MasterTemplate.AllowAutoSizeColumns = true;
    pGrid.MasterTemplate.AllowAddNewRow = false;
    pGrid.MasterTemplate.AllowDeleteRow = false;
    pGrid.MasterTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.None;
    pGrid.MasterTemplate.SelectionMode = GridViewSelectionMode.FullRowSelect;
    pGrid.TableElement.ShowTranslucentSelectionRectangle = true;
    pGrid.ShowRowHeaderColumn = false;
    pGrid.EndUpdate();
     
    foreach (GridViewDataColumn column in pGrid.Columns)
    {
        column.ReadOnly = false;
    }


    Even with the ReadOnly=false, when I changed a cell's value and clicked elsewhere, a "Data Exception" message saying "Column 'a' is read only." poped up. I put my UNION statement in a view, called the view, and everything worked as expected.
  2. Answer
    Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 10 Dec 2012 Link to this post

    Hello Philippe,

    Please check the generated DataTable Columns' ReadOnly property. In this situation the generated Columns of the DataTable can be in ReadOnly mode.

    foreach(DataColumn column in dataTable.Columns)
    {
        if(column.ReadOnly)
        {
            Console.WriteLine("Column: {0} is readonly.", column.ColumnName);
        }
    }

    I hope this helps. Let me know if you need further assistance.

    Regards,
    Julian Benkov
    the Telerik team
    Q3’12 of RadControls for WinForms is available for download (see what's new). Get it today.
  3. Philippe
    Philippe avatar
    25 posts
    Member since:
    Apr 2012

    Posted 10 Dec 2012 Link to this post

    It is indeed the DataTable's column itself that is Read only. Seems my current workaround of converting the statement to a view is a proper solution then.

    Thanks Julian.
Back to Top