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

Dynamic Content for GridView

9 Answers 161 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Thomas
Top achievements
Rank 1
Thomas asked on 25 Jun 2010, 02:34 PM
Hi,

I'm new with the RAD controls. I'm currently working with the GridView control. In all the examples, I have found so far, the fundamental assumption was always, that the content of the Grid is of a certain class, so the amount of columns is predefined.

In need something that is completely dynamically. So the same grid could have 5, 3, 2, .. columns with different heading. My program should then be able to add a row and put the value to each cell of this row. For the last part, I have currently a problem.

Background: my current task is to write with Silverlight a query tool, that allows the user to build a query against a system on the server. The user can pick e.g. name, title, subject, author etc. from a dynamic list of attributes and adds some conditions. This query is then send to the server and the result is coming back to the client / GridView to be presented to the users.

Everything is in place, the only thing missing: how my program can add a new row and then address each cell.

Since the query is dynamically (1 to n attributes in the "select" part), my program has to take care of filling the GridView.

So far, I was able to create the columns dynamically and adding them to my GridView "radGridView1".  Let's say my program has added 2 columns, one called "Id" and one call "StringValue".

Now, I would like my program to do something similar to this "pseudo" code:

row = radGridView1.AddNewRow();
row["Id"].value = "10";
row["StringValue"].value = "ABCD";

row = radGridView1.AddNewRow();
row["Id"].value = "11";
row["StringValue"].value = "OPQR";

Is that possible? What would be the correct way of doing it?


I apologize in advance if that's a trivial thing. For me, I don't see the correct way yet. Any help is appreciated.

Kind regards,
Thomas

9 Answers, 1 is accepted

Sort by
0
Milan
Telerik team
answered on 25 Jun 2010, 02:52 PM
Hi Thomas,

Could you please take a look at our Silverlight DataTable implementation. I believe it provides the functionality that you are looking for.


All the best,
Milan
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Thomas
Top achievements
Rank 1
answered on 25 Jun 2010, 04:22 PM
Hi Milan,

Yes, that seems to be what I'm looking for. Thanks a lot.

I'll try it out and let you know.

Kind regards,
Thomas
0
Jim Miles
Top achievements
Rank 1
answered on 29 Jul 2010, 09:53 PM
Hi Milan,

I need to use dynamic data with the gridview too.  I looked at your dynamic sample and was wondering if it will work with a SQL database?  I'm converting a project that uses Rad AJAX controls and this seems to be the main obstacle at the moment.  (I'm a silverlight greenhorn)

Ideally I need to pass back a sql query from the client that has dynamic columns.  Is that possible?

Thanks for any tips you can suggest.

-Jim
0
Vlad
Telerik team
answered on 30 Jul 2010, 06:53 AM
Hi Jim,

 I have similar blog post - may help you in your case.

Greetings,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Jim Miles
Top achievements
Rank 1
answered on 31 Jul 2010, 06:04 PM
Thanks Vlad!

I pointed your demo to my database and after some tinkering, it works great!  Now just  have to get it into my project.

A quick question, I'm working with a large dataset.  Do all the standard gridview features work with your datatable (more specifically the row/column virtualization)?

Thanks a million! (This should be part of Silverlight!?)

-jim
0
Jim Miles
Top achievements
Rank 1
answered on 01 Aug 2010, 02:57 AM
Hi Vlad, I spent most of today converting your dynamic data sample to VB and have it working up until the very last line of code!?  Which is when it converts the async data to the datatable.  Here is the code that I converted.  The problem is with dynamicDataCompleted, I can't cast the e.result to a datatable for the gridview ItemSource, even though it IS the data (I can see it with the debugger).  Is there a way to do this in VB? Also tried using directcast() and trycast() with no luck. Hope it's something simple I'm missing...?

Thanks,
-Jim


Public Sub New()
    InitializeComponent()

    Dim client = New dynamicDataClient  ' my dynamic data service
    AddHandler client.GetDataCompleted, AddressOf dynamicDataCompleted
    client.GetDataAsync("SELECT... from sqldb")
End Sub
 
 
Private Sub dynamicDataCompleted(ByVal sender As Object, ByVal e As GetDataCompletedEventArgs)
    dataGrid.ItemsSource = New DataTable(e.Result)
End Sub
0
Vlad
Telerik team
answered on 04 Aug 2010, 12:29 PM
Hello Jim,

 Can you verify if you have such constructor for the DataTable? Here is the VB.NET code for this:

Public Sub New(ByVal source As IEnumerable(Of Dictionary(Of String, Object)))
    If source IsNot Nothing Then
        Dim firstItem = source.FirstOrDefault()
 
        If firstItem IsNot Nothing Then
            For Each key In firstItem
                Columns.Add(New DataColumn() With { _
                 .ColumnName = key.Key, _
                 .DataType = key.Value.[GetType]() _
                })
            Next
 
            For Each item In source
                Dim row = New DataRow()
 
                For Each key In item
                    row(key.Key) = key.Value
                Next
                Rows.Add(row)
            Next
        End If
    End If
End Sub


Have you tried our converter? May help you in most cases. 

Greetings,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Jim Miles
Top achievements
Rank 1
answered on 04 Aug 2010, 08:08 PM
Hi Vlad,

I'm a greenhorn when it comes to silverlight and creating custom classes and stuff.  What I did was add a new C# project to my solution that has your data.cs and dynamic.cs classes so I wouldn't have to convert them.  Then I just converted the C# of the main application from your demo project to what I provided in my last message.  Maybe this isn't the way to do it?

I'm assuming the Public Sub New(ByVal source As IEnumerable(Of Dictionary(Of String, Object)))

Code from your message is supposed to be in the data.cs file?  Which is the same as the "DataTable" function?

Another issue I'm having is I connected your demo project to my database which has thousands of records and maybe a hundred fields.  If I create a query of about 17 fields and 1,000 records, it works fine.  If I go above 1,200 or so I start getting an error "The remote server returned an error: NotFound." in the following code of the references.cs file (the line just before the return _result).  Does the data serialization have any capacity limits?

public System.Collections.ObjectModel.ObservableCollection<System.Collections.Generic.Dictionary<string, object>> EndGetData(System.IAsyncResult result) {
    object[] _args = new object[0];
    System.Collections.ObjectModel.ObservableCollection<System.Collections.Generic.Dictionary<string, object>> _result = ((System.Collections.ObjectModel.ObservableCollection<System.Collections.Generic.Dictionary<string, object>>)(base.EndInvoke("GetData", _args, result)));
    return _result;
}

In IE, the error is:

Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)
Timestamp: Wed, 4 Aug 2010 19:00:41 UTC


Message: Unhandled Error in Silverlight Application An exception occurred during the operation, making the result invalid.  Check InnerException for exception details.   at System.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIfNecessary()
   at SilverlightApplication1.ServiceReference1.GetDataCompletedEventArgs.get_Result()
   at SilverlightApplication1.MainPage.<.ctor>b__0(Object s, GetDataCompletedEventArgs e)
   at SilverlightApplication1.ServiceReference1.MyServiceClient.OnGetDataCompleted(Object state)
Line: 1
Char: 1
Code: 0
URI: http://localhost:3745/SilverlightApplication1TestPage.aspx


I can send you my database in a support ticket if you want to see if it works for you?  My entire project hinges on getting a dynamic link to this database, as there will be different databases for different clients that are updated weekly or monthly (fields will be added/removed/changed)...

Thanks for you help
-jim

0
Nedyalko Nikolov
Telerik team
answered on 10 Aug 2010, 11:45 AM
Hi Jim Miles,

Could you please open a support ticket and send us a sample application that reproduces the problem?
Thank you in advance.

Sincerely yours,
Nedyalko Nikolov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
Thomas
Top achievements
Rank 1
Answers by
Milan
Telerik team
Thomas
Top achievements
Rank 1
Jim Miles
Top achievements
Rank 1
Vlad
Telerik team
Nedyalko Nikolov
Telerik team
Share this question
or