DataGrid column Visible issue

G

GaryDean

(one of our developers posted this and it got no answer so I'm giving it
another try)

I'm converting a DataGrid utility component that previously used the columns
array to function as it has in the past without using the columns array.
The reason for this is because it must process columns created at run time
which does not create entries in the columns array.....

My problem is that if datagrid columns created at design time are defined as
non-visible the cells in those columns still still test as visible !!

For instance if I....
Dim FirstRow As DataGridItem = mygrid.Items(0)

and then test..

If FirstRow.Cells(0).Visible = True Then

cells for the non visible column test as visible.

How can I get a true test without using the columns array??

Regards,
Gary Blakely
 
A

Alvin Bruney [MVP]

You need to catch it when it's good and ready, so you might want to handle
one of the item databound or created items (though I think item created
event may be too early).

--
________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
 
G

GaryDean

Alvin,
Sorry but I don't understand your answer. this is a datagrid object being
passed to a component. It's got nothing to do with "when" it's being looked
at. For instance column 4 is non-visible but cells in column 4 test as
visible.

--
Regards,
Gary Blakely

Alvin Bruney said:
You need to catch it when it's good and ready, so you might want to
handle one of the item databound or created items (though I think item
created event may be too early).

--
________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
-------------------------------------------------------


GaryDean said:
(one of our developers posted this and it got no answer so I'm giving it
another try)

I'm converting a DataGrid utility component that previously used the
columns
array to function as it has in the past without using the columns array.
The reason for this is because it must process columns created at run
time
which does not create entries in the columns array.....

My problem is that if datagrid columns created at design time are defined
as
non-visible the cells in those columns still still test as visible !!

For instance if I....
Dim FirstRow As DataGridItem = mygrid.Items(0)

and then test..

If FirstRow.Cells(0).Visible = True Then

cells for the non visible column test as visible.

How can I get a true test without using the columns array??

Regards,
Gary Blakely
 
A

Alvin Bruney [MVP]

ah but it has. my point was that the test is valid in the correct event
handler.

--
________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
-------------------------------------------------------


GaryDean said:
Alvin,
Sorry but I don't understand your answer. this is a datagrid object being
passed to a component. It's got nothing to do with "when" it's being
looked at. For instance column 4 is non-visible but cells in column 4
test as visible.

--
Regards,
Gary Blakely

Alvin Bruney said:
You need to catch it when it's good and ready, so you might want to
handle one of the item databound or created items (though I think item
created event may be too early).

--
________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
-------------------------------------------------------


GaryDean said:
(one of our developers posted this and it got no answer so I'm giving it
another try)

I'm converting a DataGrid utility component that previously used the
columns
array to function as it has in the past without using the columns array.
The reason for this is because it must process columns created at run
time
which does not create entries in the columns array.....

My problem is that if datagrid columns created at design time are
defined as
non-visible the cells in those columns still still test as visible !!

For instance if I....
Dim FirstRow As DataGridItem = mygrid.Items(0)

and then test..

If FirstRow.Cells(0).Visible = True Then

cells for the non visible column test as visible.

How can I get a true test without using the columns array??

Regards,
Gary Blakely
 
G

GaryDean

the datagrid was created and displayed on the page. All of the events fired
on the server a long long time ago. Now someone pushes a button on the form
and the server responds by passing the grid to a component method. At this
point the grid is a static object - it can be examined and it is indeed
complete with all the data and attributes set.

Except that cells for non-visible columns are set to visible.

--
Regards,
Gary Blakely

Alvin Bruney said:
ah but it has. my point was that the test is valid in the correct event
handler.

--
________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
-------------------------------------------------------


GaryDean said:
Alvin,
Sorry but I don't understand your answer. this is a datagrid object
being passed to a component. It's got nothing to do with "when" it's
being looked at. For instance column 4 is non-visible but cells in
column 4 test as visible.

--
Regards,
Gary Blakely

Alvin Bruney said:
You need to catch it when it's good and ready, so you might want to
handle one of the item databound or created items (though I think item
created event may be too early).

--
________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
-------------------------------------------------------


(one of our developers posted this and it got no answer so I'm giving
it another try)

I'm converting a DataGrid utility component that previously used the
columns
array to function as it has in the past without using the columns
array.
The reason for this is because it must process columns created at run
time
which does not create entries in the columns array.....

My problem is that if datagrid columns created at design time are
defined as
non-visible the cells in those columns still still test as visible !!

For instance if I....
Dim FirstRow As DataGridItem = mygrid.Items(0)

and then test..

If FirstRow.Cells(0).Visible = True Then

cells for the non visible column test as visible.

How can I get a true test without using the columns array??

Regards,
Gary Blakely
 
S

Steven Cheng[MSFT]

Hi Gary,

As for the DataGrid's Columns collection, when one of the DataGridColumn's
Visible it set to false (at design-time or runtime), it will not directly
change the underlying Cell(in the certain DataGridRow)'s Visible property
because at that time the certain Row or Cell may still hasn't been
constructed or initialized completely. I've checked the disassembly code
of the DataGrid control, the actual code logic for applying the
DataGridColumn.Visible is as below:

** we set a certain column's Visible to false (at design-time or runtime)

** the DataGrid still create each DataGridRow and cells in each row as
normal (without set the visible property on each cell)

** in the DataGrid.Render method, it will call a "PrepareControlHierarchy"
method and in this method the DataGrid will loop through all the columns
and apply the certain DataGridColumn.Visible setting to the corresponding
Cell.

Therefore, for your scenario, if you want to detect a certain Cell's
visibility, you can not use the "Visible" property since it is not
synchorized with the Column's Visible before rendering. I suggset you check
the Column's Visible property from the DataGrid's Columns collection and
determine the corresponding Cell(by index)'s visible setting. How do you
think of this?

Please feel free to let me know if you have any other concerns or questions
here.


Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================



This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

GaryDean

I can't check the Column's Visible property because columns created at run
time have no columns collection.

(my situation may make sense now that you have read my "Getting DataGrid
Header information' thread)

As it turns out I'm saved because if columns in a grid are created at run
time then those columns can't be set to non-visible because there is no
columns collection. the developer that created the datagrid would have to
set the cells themselves to non visible in the ItemDataBound event. so I
don't think I have a problem here after all.
 
S

Steven Cheng[MSFT]

Thanks for your reply Gary,

Glad that you no longer suffer this problem. Anyway, if you meet any other
issue on this later, please feel free to post here.


Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top