Hi all,
How can I display a footer in a DataGridView?
Thank you in advance,
Vanessa 11 17966
Vanessa,
You can't. You would have to custom paint the control and add the
footer (no small task, by any means). You are better off with a third-party
control that does this, or create your own control which will be displayed
below the DataGridView.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Vanessa" <Va*****@discussions.microsoft.comwrote in message
news:A2**********************************@microsof t.com...
Hi all,
How can I display a footer in a DataGridView?
Thank you in advance,
Vanessa
Thank you!
Well, what I need is to sum some columns and put the total in the last row.
If I add a row with the total, how can I prevent it to not participate in the
sort?
Thanks in advance!
Vanessa
"Nicholas Paldino [.NET/C# MVP]" wrote:
Vanessa,
You can't. You would have to custom paint the control and add the
footer (no small task, by any means). You are better off with a third-party
control that does this, or create your own control which will be displayed
below the DataGridView.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Vanessa" <Va*****@discussions.microsoft.comwrote in message
news:A2**********************************@microsof t.com...
Hi all,
How can I display a footer in a DataGridView?
Thank you in advance,
Vanessa
On Jan 7, 9:44*am, Vanessa <Vane...@discussions.microsoft.comwrote:
Hi all,
How can I display a footer in a DataGridView?
Thank you in advance,
Vanessa
Painting it is your best bet. I extended a ListView control to have a
footer and header. The footer was a summation of records as well as
the controls to allow for paging large records.
cheers
Greg
How are you putting the data in the DataGridView? Are you binding to
an existing list? If so, you might be able to influence the sort
behavior by providing a custom sort implementation. If this is a
DataTable it would be harder...
Marc
Hi Marc!
I binding via dataview of a dataset table.
Thanks
Vanessa
"Marc Gravell" wrote:
How are you putting the data in the DataGridView? Are you binding to
an existing list? If so, you might be able to influence the sort
behavior by providing a custom sort implementation. If this is a
DataTable it would be harder...
Marc
Hi Greg!
Do you have an example on how can I do this?
Thanks
Vanessa
"Greg" wrote:
On Jan 7, 9:44 am, Vanessa <Vane...@discussions.microsoft.comwrote:
Hi all,
How can I display a footer in a DataGridView?
Thank you in advance,
Vanessa
Painting it is your best bet. I extended a ListView control to have a
footer and header. The footer was a summation of records as well as
the controls to allow for paging large records.
cheers
Greg
Damn; that makes this a pain... I'll see if I can come up with
something later? (busy at the mo...)
Marc
Hi Marc,
Thank you and I will wait for your help!
Vanessa
"Marc Gravell" wrote:
Damn; that makes this a pain... I'll see if I can come up with
something later? (busy at the mo...)
Marc
I got something working by having a dummy (hidden) column to indicate
whether it is a footer row or not (well, actually it just uses a
hidden preliminary sort, so it would also work for headers etc)...
It works by hiding an extra (first) sort in IBindingList and
IBindingListView... it has to be hidden for the reversal to work
properly.
here is the usage example; I'll post the implementation
(CustomDataView) in a second post (it's a bit long... but most of it
was auto-generated)
static void Main() {
Application.EnableVisualStyles();
// declare table
DataTable dt = new DataTable("Test");
dt.Columns.Add("IsFooter", typeof(bool));
dt.Columns.Add("Caption", typeof(string));
dt.Columns.Add("Value", typeof(int));
// fill with some random data
Random rand = new Random();
int sum = 0;
for (int i = 0; i < 20; i++) {
int val = rand.Next(50);
dt.Rows.Add(false, "Row " + i.ToString(), val);
sum += val;
}
// add footer row
dt.Rows.Add(true, "Total", sum);
// display
using(Form form = new Form())
using (DataGridView grid = new DataGridView()) {
grid.Dock = DockStyle.Fill;
grid.AllowUserToAddRows = false;
form.Controls.Add(grid);
grid.DataSource = new CustomDataView(dt.DefaultView,
"IsFooter", ListSortDirection.Ascending);
grid.Columns[0].Visible = false;
Application.Run(form);
}
}
Thank you very much! It worked in a sample, so I will adapt it into
my project.
You're welcome; if you get any problems, post back ;-p
Best of luck, Marc
I don't think it would be simple to apply paging using a filter; in
particular, the code for adding/removing items (at the bottom of the
DataGridView) would be a real pain. As it happens I do have a
(predicate-oriented) filtered-list implementation up my sleeve, but I
don't think it is a good fit for what you are doing...
Being pragmatic, for paging, would it not be easier to simply copy the
page that you want from your original list into the data-bound list?
(This is what you have suggested in the last discussion)
Did I? I don't remember that, and can't see it in the archive...
For info, this discussion was really about sorting, not filtering;
they are very different beasts...
If you are paging over a very large result, consider also "virtual
mode".
Marc This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Henok Girma |
last post by:
Hello Gurus,
I want to save the state of an unbound DataGridView on my Windows Form
application to an XML file so i can later load it back..
Basically, on my form I have a DataGridView, it's got...
|
by: Rich |
last post by:
Hello,
I am populating a datagridview from a datatable and filtering the number of
rows with a dataview object. Is there a way to retrieve the rows displayed
by the datagridview into a separate...
|
by: bob |
last post by:
Can anyone tell me the best way to update a dataset while it is being
edited/viewed in the DataGridView control? Is this something that
should be inserted into one of the grid's events? or should...
|
by: Mitchell S. Honnert |
last post by:
Is there an equivalent of the DataGrid's DataGridTableStyle for the
DataGridView? If not, is there an easy way to duplicate the
DataGridTableStyle's functionality for the DataGridView?
Here's...
|
by: =?Utf-8?B?TG9zdEluTUQ=?= |
last post by:
Hi All :)
I'm converting VB6 using True DBGrid Pro 8.0 to VB2005 using DataGridView.
True DBGrid has a MultipleLines property that controls whether individual
records span multiple lines. Is...
|
by: jeastman - Hotmail |
last post by:
Hello world
Excuse, not to be written English and it helps me with a translator.
I am new programming in C#.
I made a control inheriting the DataGridView to be able to add controls done
by...
|
by: =?Utf-8?B?VmFuZXNzYQ==?= |
last post by:
Hi all!
How can I implement a DataGridView footer?
Thanks in advance!
Vanessa
|
by: JustinD30324 |
last post by:
Hello. I have a DataGridView that is bound to a DataTable. If the user
types in values for all the columns for the first row, then clicks
into a column in the second row (empty), and then clicks...
|
by: Andrus |
last post by:
I have DataGridView in virtual mode containing 3500 rows.
In code below, assigning to RowCount value to 3500 takes 8 seconds.
CPU usage goes high at this time.
Stepping by F11 into user code shows...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |