 |
|
 |
Hi ,
I have problems in the pagingdatagridview when I want to update it.
When I go to another page it loose the changes I've made.
Do you know how I can fix it?
Thankyou
anat
|
|
|
|
 |
|
 |
I have added a new method to this wonderful user control that will show the row number in each row in the grid view. This will be optional if instead of using the setdatatable you choose SetDataTablewithRowNumber.
Anat Shoshan
///
/// Sets and displays a DataTable
/// this also add a new column with the row number
/// Added by Anat Shoshan 28/07/2007
///
/// The DataTable to display.
public void SetDataTablewithRowNumber(DataTable dtin)
{
int indrow,indcol;
int maxr = dtin.Rows.Count;
DataTable tempdt = new DataTable();
System.Data.DataRow drnew;
int numcol = dtin.Columns.Count;
tempdt.Columns.Add("Row", Type.GetType("System.Int32"));
for (indcol = 0; indcol < numcol; indcol++)
{
tempdt.Columns.Add(dtin.Columns[indcol].ColumnName, dtin.Columns[indcol].DataType);
}
for (indrow = 0; indrow < maxr; indrow++)
{
drnew = tempdt.NewRow();
drnew["Row"] = indrow+1;
for (indcol = 0; indcol < numcol; indcol++)
{
drnew[dtin.Columns[indcol].ColumnName] = dtin.Rows[indrow][dtin.Columns[indcol].ColumnName];
}
tempdt.Rows.Add(drnew);
}
dsTemp.Tables.Add(tempdt.Copy());
GoToPageNumber(1);
}
|
|
|
|
 |
|
 |
Hi,
In the previous code there is an error.
In the beginning missing a line
dsTemp.Tables.Clear();
Please add! very important!
Thankyou
Anat
|
|
|
|
 |
|
 |
Hello! have just been reading through your comments and I am grateful for you letting me know your suggestions. I am very busy at the moment but hopefully within the next week I will be able to add in your modifications.
Thanks, Chris
|
|
|
|
 |
|
 |
Hi,
When pressing on sort column in the second time nothing happens and the decsending sort doesn't work.
The reason is that in the code of the overloading method OnColumnHeaderMouseClick the current DefaultView.Sort of the table is read
but then it is lost when copying to a new datatable. So I added a line to this method to keep the last sort. Another addition I thought of is that each time a sort column is asked to set the row to the first line. this is how the gridview of ASP.NET work and I think it is more convenient.
This is the new method:
protected override void OnColumnHeaderMouseClick(DataGridViewCellMouseEventArgs e)
{
if(dsTemp.Tables[0].DefaultView.Sort == "")
{
dsTemp.Tables[0].DefaultView.Sort = this.Columns[e.ColumnIndex].HeaderText + " ASC";
}
else if (dsTemp.Tables[0].DefaultView.Sort.Contains(this.Columns[e.ColumnIndex].HeaderText + " ASC"))
{
dsTemp.Tables[0].DefaultView.Sort = this.Columns[e.ColumnIndex].HeaderText + " DESC";
}
else
{
dsTemp.Tables[0].DefaultView.Sort = this.Columns[e.ColumnIndex].HeaderText + " ASC";
}
// Anat2403 fix at 27/07/2007
// The last sort will be lost if we don't keep it
string currentSort = dsTemp.Tables[0].DefaultView.Sort;
DataTable newlySorted = dsTemp.Tables[0].DefaultView.ToTable();
dsTemp.Tables.Remove(dsTemp.Tables[0]);
dsTemp.Tables.Add(newlySorted);
dsTemp.Tables[0].DefaultView.Sort = currentSort;
// int x = currentPage;
//NavClicked = "";
SetDataSet(dsTemp);
// GoToPageNumber(x);
GoToPageNumber(1);
}
besides this , this usercontrol works perfect and helped me a alot.
Anat
|
|
|
|
 |
|
 |
Hi,
I would like to know if the sort option from the gridview works here as general or there is a difference.
Thankyou
Anat
|
|
|
|
 |
|
 |
Hi,
I discussed this subject with D Strauss. You are invited to read it.
Any how your code implement the sort function very good on the whole table as I need and if after the pushing header column I give the command to go to the first page it is excellent for me.
the only problem is the implementing the opposite direction of sort which does not happen.
what can be done about this?
Thanks a lot
Anat
|
|
|
|
 |
|
 |
Thankyou I understood and did it. but how do I use the paging options in this control. I read Straus article and there everything was done in the code. Here I am not suppose to take the code just the dll ? for example I want to see the next page. What do I have to do?
Thankyou
Anat
|
|
|
|
 |
|
 |
Pass either a DataSet or DataTable to the relevant method. Call GoToNextPage(), GoToPreviousPage() etc
|
|
|
|
 |
|
 |
Hi,
Thanks a lot. I got it now and it works perfact.
What about showing the all the pages numbers like it is in the gridview of the ASP.NET that enable you to go to a specific page by choosing it from the
list of numbers?
First Previous 1 2 3 4 5 6 7 8 Next Last
- - - - - - - -
thankyou
Anat
|
|
|
|
 |
|
 |
No worries- to select a specific page use GoToPageNumber(int pagenumber).
GoToNextPage()
GoToPreviousPage()
GoToLastPage()
GoToFirstPage()
To get the current page use GetCurrentPage()
To get the toal number of pages use GetTotalPages()
To set the number of items per page set the property ItemPerPage
|
|
|
|
 |
|
 |
Hi,
I understand everything that you say but I want to see it as it looks in the gridview of ASP.NET where you see a list of all the number of pages and you choose. Now that I think of it I understand that I have to prepare it as I prepare the buttons of next and previous. O.K. I will do it but I see one problem and maybe you suggest how to solve it:
suppose I found that there are 500 pages. How shall I present it so that the user will just choose the page number? Do you know how it looks in the ASP.NET?
Thank you
anat
|
|
|
|
 |
|
 |
Please can you explain or give me a link how to do the import?
"import it into your toolbox in Designer mode"
I got the dll from the release but how do I enter it to a new project?
Thankyou
Anat
|
|
|
|
 |
|
 |
Hello,
When running Visual Studio (I am in 2005) while designing your form there should be a toolbox containing the various controls you can add to a form. If not hit Ctrl-X and it will be displayed.
Right click anywhere on the Toolbox and there will be a menu item called Choose Items...
Click this.
In the .NET Components tab click Browse.
Navigate to PagingDataGridView.dll and select it.
Make sure the check box next to it is checked, click ok, and add the control to the form as any other.
|
|
|
|
 |
|
 |
You instanciated a DataSet in this method called dsTempSubSet that has no purpose. It's not being used. (See code below from the sourcecode you provided for download) Other than that, it is exactly what I wanted to do in my next article. By the way, in the Background section of your article you refer to me as "D Straus's ". It should be "D Strauss'".
public void GoToPreviousPage()
{
DataSet dsTempSubSet = new DataSet();
DataRow[] rows = new DataRow[RowsPerPage];
if(CurrentPage != 1)
{
GoToPageNumber(CurrentPage - 1);
//CurrentPage = dsTemp.Tables[0].Rows.Count / RowsPerPage;
//CurrentPage++;
}
}
|
|
|
|
 |
|
 |
Thanks for that, I have modified the code so that GoToNextPage() GoToPreviousPage() and GoToLastPage() now use GoToPageNumber(int), and I have removed the instantiated objects that are not used.
|
|
|
|
 |