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

Problem with empty datasource.

5 Answers 139 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Espen
Top achievements
Rank 1
Espen asked on 09 Jan 2008, 05:53 PM
I am having a problem with the RadGridView when setting the datasource to null.

I have to dynamically generate a table I use for datasource. As I add or subtract columns everything seems to be working. The problem comes when I remove the last displayed column, the view still shows the column with all the rows. Although if I click a row I get a RowNotInTableException. Am I doing something wrong?

The pertinent code is : 

dataGridView1.GridElement.BeginUpdate();
dataGridView1.DataSource = CalculateTable(...);
dataGridView1.GridElement.EndUpdate();

The CalculateTable method returns null if there is nothing to do. Should I return an empty table instead, or is it some update thing I am not doing?

5 Answers, 1 is accepted

Sort by
0
Julian Benkov
Telerik team
answered on 10 Jan 2008, 09:04 AM
Hi Espen,

Thank you for contacting us.

We would like to investigate this scenarion in additional detail. Please send us a simple project reproducing the behavior you describe. It will help us address any potential issue faster.

If you have any additional questions, please write us again.

Best wishes,
Julian Benkov
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Espen
Top achievements
Rank 1
answered on 10 Jan 2008, 04:49 PM
Is there a way I can attach the project to a posting? Or should I send it somewhere else?


It is probably easier to just reproduce it yourself by creating a new windows app, add two buttons and a radgridview.

on button 1 (columns) click event:

gridList.GridElement.BeginUpdate();
gridList.DataSource = CalculateTable(

false);
gridList.GridElement.EndUpdate();


on button 2 (null) click event:

gridList.GridElement.BeginUpdate();
gridList.DataSource = CalculateTable(

true);
gridList.GridElement.EndUpdate();

and the last method :

private DataTable CalculateTable(bool returnNullTable)
{
   
if (returnNullTable == true)
       
return null;

    DataTable dt = new DataTable("TestTable");
    dt.Columns.Add(
new DataColumn("TestColumn", Type.GetType("System.String")));

    string[] item = new string[1];
    item[0] =
"test 0";
    dt.Rows.Add(item);
    item[0] =
"test 1";
    dt.Rows.Add(item);
    item[0] =
"test 2";
    dt.Rows.Add(item);
   
return dt;
}


if you click columns, then null, the rows are still present, and if you select a row you go kaboom. Am I doing something wrong?
0
Julian Benkov
Telerik team
answered on 11 Jan 2008, 01:34 PM
Hello Espen,

Sorry for the inconvenience.

We have found an issue with the DataSource when it is reset to null in RadGridView in our current release. For the time being, you can use this workaround:

on button 2 (null) click event
 
gridList.GridElement.BeginUpdate(); 
gridList.DataSource = CalculateTable(true); 
((GridTableElement)gridList.GridElement).TableBodyElement.Children.Clear(); 
gridList.GridElement.EndUpdate(); 
 

The issue will be addressed for our next release. Your Telerik points have been updated.

We'll be glad to help you with any additional questions.

Best wishes,

Julian Benkov
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Espen
Top achievements
Rank 1
answered on 11 Jan 2008, 01:46 PM
Another workaround that can be used (and that I am using now) is to return an empty table instead of null. So the method looks more like this:

private

DataTable CalculateTable(bool returnNullTable)
{
    DataTable dt = new DataTable("TestTable");
    if (returnNullTable == true)
        return dt;
   ...
}

0
Kiril
Telerik team
answered on 11 Jan 2008, 02:11 PM
Hello Espen,

Thank you for sharing your workaround with the community. Your Telerik points have been updated.

Sincerely yours,
Kiril
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
GridView
Asked by
Espen
Top achievements
Rank 1
Answers by
Julian Benkov
Telerik team
Espen
Top achievements
Rank 1
Kiril
Telerik team
Share this question
or