473,386 Members | 1,823 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Getting DataGrid Header information

I am writing a method in a component that gets passed a 1.1 Datagrid. The
datagrid's columns were created at run time meaning it has no columns
collection.

How can I access Header and Footer data in the grid?

It's not in the grid.items collection - only rows there. there is no
grid.header or grid.footer.

--
Regards,
Gary Blakely
Oct 7 '06 #1
7 7434
No, but there is a header row and a footer row and you can query row type.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com

*************************************************
Think outside of the box!
*************************************************
"GaryDean" <Ga******@newsgroups.nospamwrote in message
news:OJ**************@TK2MSFTNGP03.phx.gbl...
>I am writing a method in a component that gets passed a 1.1 Datagrid. The
datagrid's columns were created at run time meaning it has no columns
collection.

How can I access Header and Footer data in the grid?

It's not in the grid.items collection - only rows there. there is no
grid.header or grid.footer.

--
Regards,
Gary Blakely


Oct 8 '06 #2
Hi Gary,

C#
MyGrid.Controls[0].Controls[0] ' header
MyGrid.Controls[0].Controls[MyGrid.Controls[0].Controls.Count - 1] ' footer

Vb.Net
MyGrid.Controls(0).Controls(0) ' header
MyGrid.Controls(0).Controls(MyGrid.Controls(0).Con trols.Count - 1) ' footer

Remeber to check if the ShowHeader and ShowFooter properties are set to true
before running the above code (plus the range check if
(MyGrid.Controls[0].Count 0) ...

Hope this helps

--
Milosz Skalecki
MCP, MCAD
"GaryDean" wrote:
I am writing a method in a component that gets passed a 1.1 Datagrid. The
datagrid's columns were created at run time meaning it has no columns
collection.

How can I access Header and Footer data in the grid?

It's not in the grid.items collection - only rows there. there is no
grid.header or grid.footer.

--
Regards,
Gary Blakely
Oct 8 '06 #3
Yes. that does it. Thanks much!

--
Regards,
Gary Blakely
"Milosz Skalecki" <mi*****@REMOVEITwp.plwrote in message
news:3E**********************************@microsof t.com...
Hi Gary,

C#
MyGrid.Controls[0].Controls[0] ' header
MyGrid.Controls[0].Controls[MyGrid.Controls[0].Controls.Count - 1] '
footer

Vb.Net
MyGrid.Controls(0).Controls(0) ' header
MyGrid.Controls(0).Controls(MyGrid.Controls(0).Con trols.Count - 1) '
footer

Remeber to check if the ShowHeader and ShowFooter properties are set to
true
before running the above code (plus the range check if
(MyGrid.Controls[0].Count 0) ...

Hope this helps

--
Milosz Skalecki
MCP, MCAD
"GaryDean" wrote:
>I am writing a method in a component that gets passed a 1.1 Datagrid.
The
datagrid's columns were created at run time meaning it has no columns
collection.

How can I access Header and Footer data in the grid?

It's not in the grid.items collection - only rows there. there is no
grid.header or grid.footer.

--
Regards,
Gary Blakely

Oct 9 '06 #4
Hi Gary,

Milosz's suggestion is directly access the DataGrid's Controls collection
to retrieve the Header and Footer child control, this does work though it
require us to have clear view of the DataGrid's control tree (you can view
page's control tree by turn on the page's output trace). However, I would
still recommend that we avoid this as much as possible since accessing
child control through index only is dangerous which may break between
different version changes.

BTW, are you using the DataGrid in ASP.NET 1.1 application or ASP.NET 2.0
application. If you're using it in ASP.NET 2.0 or plan to upgrade the
application to ASP.NET 2.0, you can consider the GridView control(specific
to ASP.NET 2.0) since it has naturally expose the "Footer" and "Header" as
two public properties (FooterRow and HeaderRow).

Please feel free to post here if you need any further help.
Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 9 '06 #5
Steven,

I agree with you but my answer is based on his post (datagrid, asp.net 1.1,
reference is passed - so i quess you cannot do it in proper way i.e. in
itemcreated) :)

Regards
--
Milosz Skalecki
MCP, MCAD
"Steven Cheng[MSFT]" wrote:
Hi Gary,

Milosz's suggestion is directly access the DataGrid's Controls collection
to retrieve the Header and Footer child control, this does work though it
require us to have clear view of the DataGrid's control tree (you can view
page's control tree by turn on the page's output trace). However, I would
still recommend that we avoid this as much as possible since accessing
child control through index only is dangerous which may break between
different version changes.

BTW, are you using the DataGrid in ASP.NET 1.1 application or ASP.NET 2.0
application. If you're using it in ASP.NET 2.0 or plan to upgrade the
application to ASP.NET 2.0, you can consider the GridView control(specific
to ASP.NET 2.0) since it has naturally expose the "Footer" and "Header" as
two public properties (FooterRow and HeaderRow).

Please feel free to post here if you need any further help.
Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 9 '06 #6
Hi Steven,
A couple years ago I wrote a component called PrintGrid
(http://www.deanblakely.com/PrintGrid.aspx). The component creates a
Crystal Report of any DataGrid. It worked for the 1.1 DataGrid but I wrote
it using the Columns collection (my mistake) so it would not work for
columns created at run time. I have given it away to several hunderd
developers that are probably still using it.

Now I am improving the component by (1) converting it so it will work for
columns created at run time for the DataGrid and (2) work for the new 2.0
GridView. All the developer has to do is call a method in my component,
passing either a DataGrid or a GridView object to print a report.

So, I understand that you are suggesting that using the controls collection
may not be a safe thing to do. Ok, but what is my alternative? How can I
get the Header and Footer text without using the Columns Collection and
without using the Controls Collection for the 1.1 DataGrid?

Later, when I'm working on the GridView it looks like it will be easier
since there are the two properties you mention. But, PrintGrid must provide
functionality for the 1.1 DataGrid for a long time because it will be used
for a long time.
--
Regards,
Gary Blakely
"Steven Cheng[MSFT]" <st*****@online.microsoft.comwrote in message
news:bf**************@TK2MSFTNGXA01.phx.gbl...
Hi Gary,

Milosz's suggestion is directly access the DataGrid's Controls collection
to retrieve the Header and Footer child control, this does work though it
require us to have clear view of the DataGrid's control tree (you can
view
page's control tree by turn on the page's output trace). However, I would
still recommend that we avoid this as much as possible since accessing
child control through index only is dangerous which may break between
different version changes.

BTW, are you using the DataGrid in ASP.NET 1.1 application or ASP.NET 2.0
application. If you're using it in ASP.NET 2.0 or plan to upgrade the
application to ASP.NET 2.0, you can consider the GridView control(specific
to ASP.NET 2.0) since it has naturally expose the "Footer" and "Header" as
two public properties (FooterRow and HeaderRow).

Please feel free to post here if you need any further help.
Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no
rights.

Oct 9 '06 #7
Thanks for your followup Gary,

So I've got the point here that your helper method will accept both 1.1
DataGrid and 2.0 Gridview class instance. Thus, I agree that except
directly access the Controls collection, there is no other means to get
the header and footer control collection for 1.1 DataGrid.

Anyway, I still suggest you add more protection code (like check null
reference) in your code which access Header/Footer through index in
Controls collection.

Please feel free to let me know if there is anything else we can help.
Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 10 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: | last post by:
How I can autosize a DataGrid after then associate a Datasource=Dataset in Smart Devices applications or Windows forms application?? That same?? -- Cumprimentos, David de Passos...
2
by: DelphiBlue | last post by:
I have a Nested Datagrid that is using a data relations to tie the parent child datagrids together. All is working well with the display but I am having some issues trying to sort the child...
0
by: amber | last post by:
Okay, there is some wierdness going on with my datagrid... I'm trying to make my column header 2 lines high. If I go into the Form - InitializeComponent code, and change the line: ...
2
by: Josef Meile | last post by:
Hi, I'm using a ComboBox, some Textboxes, and a DataGrid to represent a many-to-many relationship between Person and Course. Each time that I change the value in the ComboBox (which for now is...
1
by: David Lozzi | last post by:
Hi, I'd like to customize a header in a DataGrid. I want to add a link in the header, as well as pull a recordset's ID. I am using a TemplateColumn so that I can hold several lines of...
3
by: AMD Desktop | last post by:
Hi, I need to add a header to a datagrid. This is the code I am trying to use: Dim dgStaffingReport As New DataGrid Dim dgitem As New DataGridItem(0, 0, ListItemType.Header) Dim mycell...
0
by: Daniel Doyle | last post by:
Hello and apologies in advance for the amount of code in this post. I've also sent this message to the Sharepoint group, but thought that ASP.NET developers may also be able to help, even though...
2
by: Santosh | last post by:
Dear all i want to bind data to datagrid header template i am wrtting follwing code it is displaying data with in item template not but it is display data in header template <asp:DataGrid...
2
by: =?Utf-8?B?Y3JlYXZlczA2MjI=?= | last post by:
I have a nested datagrid in a xaml file, the parent datagrid loads the vendor information and the details loads the documents for that vendor in a datagrid. Everything is working fine until I click...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
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
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
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,...
0
jinu1996
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.