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
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 >>
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.
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 >>
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.
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 >>
http://www.weintraub.net/marc/WpfApplication1.zip
I will review the blog post.
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 >>
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.
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.
Vlad
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
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.
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?
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.
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?
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.