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

Grid and strongl-typed DataTable problem

3 Answers 69 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Erez
Top achievements
Rank 1
Erez asked on 18 Jun 2009, 07:42 AM

Hello,

I have connected the DefaultView property of a strong-typed datatable to the ItemsSource of the Telerik grid
and most of the data from the grid is not showing in the grid.

When I connect the datatable and not its default view, everything works fine.

This seems to occur when working with a strong-type datatable and not when I create a datatable on the fly.

 

Help will be most appreciated,

 

Erez

3 Answers, 1 is accepted

Sort by
0
Hristo Deshev
Telerik team
answered on 18 Jun 2009, 08:49 AM
Hello Erez,

I can't reproduce this on my end. How do you define your columns? Do you use UniqueName or DataMemberBinding? Can you check if your bindings or names are the same as the column/property names?

I am attaching a sample project that uses a strongly typed data table and binds to its default view. Can you reproduce the problem there?

Regards,
Hristo Deshev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Erez
Top achievements
Rank 1
answered on 18 Jun 2009, 09:12 AM

Hi Hristo,

I took you code and made a few changes.
It seems that the problem occurs when the DataTable is empty.
As you can see below, I have remarked out the
"adapter.Fill(products); " row
and added code to add a new line to the datatable.

When I test it, it seems that the data is inputed into the datatable, however the grid
does not show any values in the ProductID column.

I am not sure now that the issue is specificaly tide to strog-type datatable, however it still seems a bit buggy.


Here is the code:

public Window1()
        {
            InitializeComponent();

            var adapter = new NorthwindTableAdapters.ProductsTableAdapter();
            var products = new Northwind.ProductsDataTable();
            /* adapter.Fill(products); */
            RadGridView1.ItemsSource = products.DefaultView;

        }

        private void MyAddRow(bool bAddEmptyRow)
        {
            DataTable dt = ((DataView)RadGridView1.ItemsSource).Table;

            DataRow r = dt.NewRow();
            int index = -1;

            if (dt.Rows.Count > 0)
            {
                index = (int)dt.Rows[dt.Rows.Count - 1]["ProductID"] + 1;

                if (bAddEmptyRow == false)
                {
                    r.ItemArray = dt.Rows[dt.Rows.Count - 1].ItemArray;
                }
            }
            else
            {
                // All of these are must columns.
                index = 1;
            }

            r["ProductID"] = index;
            r["ProductName"] = "Name" + index;
            r["Discontinued"] = 0;

            if (bAddEmptyRow == true)
            {
                //r["Approved"] = 0;
                //r["Year"] = DateTime.Now.Year;
                //r["VersionID"] = 1;
                //r["ActivityName"] = "my test";
                //r["OBSID"] = 555;
                //r["ApprovalStatusID"] = 0;
            }

            dt.Rows.Add(r);
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            MyAddRow(true);
        }


Thanks,

Erez
0
Accepted
Hristo Deshev
Telerik team
answered on 19 Jun 2009, 01:03 PM
Hello Erez,

I reproduced the problem. I too think this is a bug with the automatic binding creation code that will produce a cell value binding from the column UniqueName, if a DataMemberBinding has not been specified.

I can offer a simple workaround: specify your bindings explicitly like this:

<telerik:RadGridView Name="RadGridView1" AutoGenerateColumns="False" Grid.Row="1"
    <telerik:RadGridView.Columns> 
        <telerik:GridViewDataColumn DataMemberBinding="{Binding ProductID}" HeaderText="Product ID"></telerik:GridViewDataColumn> 
        <telerik:GridViewDataColumn DataMemberBinding="{Binding ProductName}" HeaderText="Product Name"></telerik:GridViewDataColumn> 
    </telerik:RadGridView.Columns> 
</telerik:RadGridView> 
 

Thanks for the report! I have updated your Telerik points.

Sincerely yours,
Hristo Deshev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
GridView
Asked by
Erez
Top achievements
Rank 1
Answers by
Hristo Deshev
Telerik team
Erez
Top achievements
Rank 1
Share this question
or