Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7026247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:05:31+00:00 2026-05-28T00:05:31+00:00

Background information: I have the following code in a WCF service. GetDataTable returns a

  • 0

Background information:
I have the following code in a WCF service. GetDataTable returns a System.Data.DataTable based on a call to a SQL database with the query parameter passed.

public IEnumerable<Dictionary<string, object>> GetData(string *query*) {
    var table = GetDataTable(query);
    var columns = table.Columns.Cast<DataColumn>();
    var dict = table.AsEnumerable()
        .Select(r => columns.Select(c => new {
            Column = c.ColumnName,
            Value = r[c]
        })
        .ToDictionary(i => i.Column, i => i.Value != DBNull.Value ? i.Value : null));
    return dict;
}

I have a Silverlight application that makes a call to GetData, passing a string, and I receieve results. However, the fields I have in my GridView are “Comparer”, “Count”, “Keys”, and “Value”.

Silverlight code snippet

    WCFCLIENT oData = new WCFCLIENT ();
    oData.GetData+= new EventHandler<GetDataCompletedEventArgs>(oData_GetData);
    oData.GetData(*sqlquery*);
  }
}

void oData_GetDataCompleted(object sender, GetDataCompletedEventArgs e) {
  if (e.Error == null) {
    rdpPaging.Source = e.Result;    
    rgvDataResults.ItemsSource = rdpPaging.Source;
}

My Question is two-fold

  1. Is the code I’m using to create the Dictionary wrong somehow?
  2. If the code is correct, how do I properly set the DataGrid’s data source so it shows the columns and rows returned by the SQL call?

I have tried binding to different properties of the e.Result variable, but have had similar results.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T00:05:32+00:00Added an answer on May 28, 2026 at 12:05 am

    You have two options …

    1. Bind the dictionary directly with the DataGrid but keep the columns non autogenerated. Create the columns manually by loopiing through all the keys in first item (dictionary) of the total list and use custom binding/converter for showing proper data.

    2. I am using this with teleric GridView but I think this will work with normal Silverlight datagrid as well.

      http://blogs.telerik.com/blogs/posts/09-04-23/lightweight-datatable-for-your-silverlight-applications.aspx

    You can convert your list into datatable at clientside and use this approach easily.

    [Update] Code example of the first option

                D_Grid.ItemsSource = Data;        // Data is the collection of dictionary
                foreach (var key in Data[0].Keys)
                {
                        GridViewDataColumn dataCol = null;
                        dataCol = (GridViewDataColumn)D_Grid.Columns[key];
                        if (dataCol == null)
                        {
                            dataCol = new GridViewDataColumn();
                            dataCol.Header = key;
                            dataCol.UniqueName = key;                          
                            dataCol.DataMemberBinding = new Binding()
                            {
                                Converter =new GridConverter(key); // Put your converter that will take the key and return the value from that key.
                            };
                            D_Grid.Columns.Add(dataCol);
    
                        }
                    }
    

    Converter code. Please note you need to store the key in the converter that you pass in the constructor.

    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                if (value is Dictionary<string, object>)
                {
                    var input = (Dictionary<string, object>)value;
                    if (input.ContainsKey(_key))
                        return input[_key];
                }   
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code that should display some information about ContactLists in a
Background information: I have been writing code to control a device attached by a
I am using the following code: <ListBox x:Name=lbItems Grid.Row=1 Margin=2> <ListBox.Template> <ControlTemplate> <Border Background={StaticResource
I have a Silverlight application that needs to scroll some data (like stock information)
I have the following code: const int PROVIDER_RSA_FULL = 1; const string CONTAINER_NAME =
Background I have the following function, which ranks results by how closely they match
I have the following code to layout the menu for my page: //Header Conainer
Background Information: Ultimately, I would like to write an emulator of a real machine
As usual, some background information first: Database A (Access database) - Holds a table
And if you do, can you give some background information on the implementation and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.