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

Setting IsVisible in AutoGeneratingColumn Event Method kills grid input

14 Answers 147 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Marc Weintraub
Top achievements
Rank 1
Marc Weintraub asked on 10 May 2012, 10:01 PM
I inherited this code from an ex-employee and trying to fix a bug.

When entering data into a GridView and there is a nonVisible column, you can sometimes only enter in 2 rows before you can't type anything else into the cell.

I found that when a column is set to "IsVisible = false" in the "AutoGeneratingColumn" event method it behaves like this. When I comment this line out, you can enter 'n' number of rows. (of course you will see the column that is suppose to be hidden.

XAML
<Telerik:RadGridView x:Name="grdTableData"
                     Grid.Row="1"
                     TabIndex="6"
                     ShowInsertRow="True"
                     CanUserSortColumns="False"
                     ActionOnLostFocus="None"
                     ColumnWidth="*"
                     FontSize="12"
                     Margin="5"
                     SelectionMode="Single"
                     BorderThickness="1"
                     IsFilteringAllowed="False"
                     ShowGroupPanel="False"
                     BorderBrush="Black"
                     AutoGenerateColumns="True"
                     AlternationCount="2"
                     RowEditEnded="grdTableData_RowEditEnded"
                     AutoGeneratingColumn="grdTableData_AutoGeneratingColumn">
</Telerik:RadGridView>


C#
public partial class MainWindow : Window
{
    DataTable dt = new DataTable();
    DataTable emptyDT = new DataTable();
    public MainWindow()
    {
        InitializeComponent();
          
        emptyDT.Columns.Add("Hidden");
        emptyDT.Columns.Add("Lookup");
        grdTableData.ItemsSource = emptyDT.DefaultView;
        dt.Columns.Add("Hidden");
        dt.Columns.Add("Lookup");
        grdTableData.ItemsSource = dt.DefaultView;
    }
    private void grdTableData_RowEditEnded(object sender, Telerik.Windows.Controls.GridViewRowEditEndedEventArgs e)
    {
        ReadDataPage();
    }
    private void ReadDataPage()
    {
        // clear grid
        grdTableData.ItemsSource = emptyDT.DefaultView;
        // repopulate grid
        grdTableData.ItemsSource = dt.DefaultView;
    }
    private void grdTableData_AutoGeneratingColumn(object sender, Telerik.Windows.Controls.GridViewAutoGeneratingColumnEventArgs e)
    {
        if( e.Column.Header.ToString() == "Hidden" )
            e.Column.IsVisible = false;         // <---- COMMENT THIS and it works.
    }
}

14 Answers, 1 is accepted

Sort by
0
Yordanka
Telerik team
answered on 11 May 2012, 12:58 PM
Hi Marc,

I am not sure why you change ItemSource of the grid on RowEditEnded? Can you describe the scenario you want to achieve?
 
Greetings,
Yordanka
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Marc Weintraub
Top achievements
Rank 1
answered on 11 May 2012, 05:40 PM
Thanks for getting back to me!

To be honest, I'm not sure. This feature was done by another programmer who is no longer with the company.

Alright, I just looked at the code more. I think I know why he has done what he has done.

I changed the code to populate the grid with .DataContext and set "ItemsSource="{Binding}"" in the XMAL. But now the "Click here to add new item" does not respond and I can't type anything in.

Also, we are using a paging scheme where that ReadDataPage() method calls a function to query the DB for the 20 items based on the page#. When the page Next or Back is pressed, it calls ReadDataPage() again with a different page#. That doesn't work either. It seems that the object that is assigned to DataContext is being changed, but the grid is not.

In ReadDataPage():
// Database has 21 rows to display 
  
// pageIndex is 0, pageSize = 20
_dtResults = SomeMethodToGetDT(pageIndex, pageSize); 
// Now, _dtResults has 20 rows 
    
// Check what's in grdTableData 
DataTable dtTemp = grdTableData.ItemsSource as DataTable; 
// dtTemp has 0 rows 

Now, when I click for the next Page:
// Database has 21 rows to display 
  
// pageIndex is 1, pageSize = 20
_dtResults = SomeMethodToGetDT(pageIndex, pageSize); 
// Now, _dtResults has 1 row
    
// Check what's in grdTableData 
DataTable dtTemp = grdTableData.ItemsSource as DataTable; 
// dtTemp has 20 rows 


Why is dtTemp a step behind? Am I missing something? I didn't find anything in the code that changes grdTableData otherwise.
0
Yordanka
Telerik team
answered on 14 May 2012, 10:38 AM
Hello Marc,

Why not using RadDataPager instead of this approach with ReadDataPage()?
 
All the best,
Yordanka
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Marc Weintraub
Top achievements
Rank 1
answered on 14 May 2012, 02:19 PM
To be honest. I don't know. I'm not sure why he didn't use it. Right now, I don't know if I'll be able to learn and implement the DataPager in time.

Edit: Looking at your example you linked to, does this mean that every line has to be retrieved from the database and the DataPager will only just display the "PageSize" only? If this is how it works, this is probably why the previous developer went the route he did. He felt that retrieving thousands and thousands of records at once wouldn't be effective.

But I ask, is there a bug the controls when it's used in the same way I'm using it?

Marc.
0
Yordanka
Telerik team
answered on 14 May 2012, 02:46 PM
Hi Marc,

When using RadDataPager it shows only one page with loaded data and it is not aware that there are other items to be loaded. You can find extended description for the purpose of RadDataPager in this blog post.

As you page the data implementing a custom paging, I cannot be sure where the problem comes from and what is causing it.
 
Kind regards,
Yordanka
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Marc Weintraub
Top achievements
Rank 1
answered on 14 May 2012, 03:27 PM
Below is a link to a sample project (where the above test code came from) that is exibiting the issue. I'm not paging, but rather repopulating the grid.

http://www.weintraub.net/marc/WpfApplication1.zip

I will review the blog post.
0
Yordanka
Telerik team
answered on 16 May 2012, 02:11 PM
Hello Marc,

As I have mentioned in my first post, the approach for changing the ItemsSource in RowEditEnded is not quite correct and the result can be unexpected, as the one you get.
Could you share with us what is the final goal of this implementation? We will be glad to help you and to propose you an appropriate solution.
 
Kind regards,
Yordanka
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Marc Weintraub
Top achievements
Rank 1
answered on 13 Aug 2012, 09:17 PM
Hi. Thanks for the reply and sorry for the long delay in replying. I got caught up in other tasks and now back to this one.

The final goal of this feature is to display a table from a database and display it while hidding certain columns as needed. Then when an row is Inserted or edited, it updates the database. Getting the data frin and updating the database works fine.

Since I'm fairly new to WPF, what would you recommend for the following requirements:

- Paging [database table can be 10k in size]
- Load only one page of data from the database at a time
- Row is editable and updates the database when done editing
- New rows can be inserted from the grid and inserts into the database when done

I'm currently looking into the DataPager to see if this fits all the above criteria.
0
Vlad
Telerik team
answered on 14 Aug 2012, 05:47 AM
Hello,

 Using RadGridView, RadDataPager and RadEnitiyFrameworkDataSource you can achieve all of your requirements in most cases completely codeless.

Please check your local copy of our demos for more info and code. 

Greetings,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Marc Weintraub
Top achievements
Rank 1
answered on 14 Aug 2012, 03:33 PM
Vlad, thanks for the quick reply.

From what I know about EntityFramework is that you need a predefined database / table schema. If that is the case then it won't work because the table schema is dynamic depending on how the customer was set up and can change at any time.

Marc.
0
Marc Weintraub
Top achievements
Rank 1
answered on 21 Aug 2012, 05:46 PM
Any other ideas?

During my research, am I right to read that the ASP.NET RadGridView has properties such as AllowCustomPageing and VirtualItemCount that will allow for what I'm trying to do? Why isn't this in the WPF version?
0
Vlad
Telerik team
answered on 22 Aug 2012, 06:02 AM
Hi,

 If you want custom paging you can implement IPagedCollectionView. I've attached small example project for reference. 

Greetings,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Marc Weintraub
Top achievements
Rank 1
answered on 22 Aug 2012, 07:15 PM
Vlad, Thanks for this sample project. Like I mentioned before, I'm fairly new to WPF so this has tremendiously helped me see how it all works together!

Now, I'm trying to implement a feature we have in our app, which is the ability to Add Rows from the RadGridView. After adding the 'ShowInsertRow="True"' value, it still didn't allow me to utilitze the "Click here to add new item".

After searching, I found that the type of collection has to allow this...
http://www.telerik.com/community/forums/silverlight/gridview/clicking-add-new-item-does-not-work-when-showinsertrow-true.aspx

What can I do to get this working?
0
Vlad
Telerik team
answered on 28 Aug 2012, 05:52 AM
Hello,

 Generally to insert records the collection should be at least IList. 

Regards,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
GridView
Asked by
Marc Weintraub
Top achievements
Rank 1
Answers by
Yordanka
Telerik team
Marc Weintraub
Top achievements
Rank 1
Vlad
Telerik team
Share this question
or