Hi Maher,
Thank you for writing.
Yes, it is possible to achieve the desired behavior. Please note, however, this type of functionality is not provided out of the box. In order to accomplish your
task you would need to sync the labels with the current
PageSize and total rows count values. If I have understood correctly you would also like the text box to display the page size.
In order the text box to be functional so that the
RadGridView.PageSize changes whenever there is a new input, we are also going to need to unsubscribe it from the
KeyDown event and implement our own delegate. Please see my code snippet below:
public
partial
class
Form1 : Form
{
public
Form1()
{
InitializeComponent();
new
RadControlSpyForm().Show();
this
.radGridView1.DataSource =
this
.GetData(1000);
this
.radGridView1.EnableFiltering =
true
;
this
.radGridView1.EnablePaging =
true
;
this
.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
this
.radGridView1.Rows.CollectionChanged += Rows_CollectionChanged;
this
.radGridView1.PageChanged += radGridView1_PageChanged;
}
protected
override
void
OnLoad(EventArgs e)
{
base
.OnLoad(e);
CommandBarTextBox pageNumberTextBox =
this
.radGridView1.GridViewElement.PagingPanelElement.PageNumberTextBox;
EventInfo ei = pageNumberTextBox.GetType().GetEvent(
"KeyDown"
, BindingFlags.Public | BindingFlags.Instance);
if
(ei !=
null
)
{
Type delType = ei.EventHandlerType;
MethodInfo mi =
this
.radGridView1.GridViewElement.PagingPanelElement.GetType().GetMethod(
"PageNumberTextBox_KeyDown"
, BindingFlags.NonPublic | BindingFlags.Instance);
if
(mi !=
null
)
{
Delegate del = Delegate.CreateDelegate(delType,
this
.radGridView1.GridViewElement.PagingPanelElement, mi);
ei.RemoveEventHandler(pageNumberTextBox, del);
this
.radGridView1.GridViewElement.PagingPanelElement.PageNumberTextBox.KeyDown += PageNumberTextBox_KeyDown;
}
}
}
protected
override
void
OnShown(EventArgs e)
{
this
.ChangePageLabels();
}
private
void
PageNumberTextBox_KeyDown(
object
sender, KeyEventArgs e)
{
if
(e.KeyCode != Keys.Enter)
{
return
;
}
int
pageSize = -1;
if
(
int
.TryParse(((RadTextBoxItem)sender).Text,
out
pageSize))
{
this
.radGridView1.PageSize = pageSize;
this
.ChangePageLabels();
}
}
private
void
Rows_CollectionChanged(
object
sender, Telerik.WinControls.Data.NotifyCollectionChangedEventArgs e)
{
this
.ChangePageLabels();
}
private
void
radGridView1_PageChanged(
object
sender, EventArgs e)
{
this
.ChangePageLabels();
}
private
void
ChangePageLabels()
{
this
.radGridView1.GridViewElement.PagingPanelElement.PageLabel.Text =
"Page Size"
;
this
.radGridView1.GridViewElement.PagingPanelElement.NumberOfPagesLabel.Text =
this
.radGridView1.Rows.Count +
""
;
this
.radGridView1.GridViewElement.PagingPanelElement.PageNumberTextBox.TextBoxElement.TextBoxItem.Text =
this
.radGridView1.PageSize +
""
;
}
private
DataTable GetData(
int
count)
{
DataTable dt =
new
DataTable();
dt.Columns.Add(
"Name"
,
typeof
(
string
));
dt.Columns.Add(
"Age"
,
typeof
(
int
));
dt.Columns.Add(
"Date"
,
typeof
(DateTime));
dt.Columns.Add(
"Bool"
,
typeof
(
bool
));
for
(
int
i = 0; i < count; i++)
{
dt.Rows.Add(
"Name "
+ i, i, DateTime.Now.AddMinutes(i), i % 2 == 0 ?
true
:
false
);
}
return
dt;
}
}
Regarding your other question about the
ChildRows, this property returns the rows in the current template. When paging is enabled it will be the value of the
PageSize property. If you apply a filter it will take into consideration the filtered rows as well. More information is available here:
Rows vs ChildRows.
I am also sending you a short video showing the result on my end.
I hope this helps. Should you have further questions please do not hesitate to write back.
Regards,
Hristo Merdjanov
Telerik
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 Feedback Portal and vote to affect the priority of the items