This is a migrated thread and some comments may be shown as answers.

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

2 Answers 89 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Philippe
Top achievements
Rank 2
Philippe asked on 05 Dec 2012, 04:38 PM
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 Answers, 1 is accepted

Sort by
0
Accepted
Julian Benkov
Telerik team
answered on 10 Dec 2012, 04:36 PM
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.
0
Philippe
Top achievements
Rank 2
answered on 10 Dec 2012, 04:43 PM
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.
Tags
GridView
Asked by
Philippe
Top achievements
Rank 2
Answers by
Julian Benkov
Telerik team
Philippe
Top achievements
Rank 2
Share this question
or