Re: Hiding DataGrid Columns when AutoGenerateColumns="true"
- From: "Eliyahu Goldin" <REMOVEALLCAPITALSeEgGoldDinN@xxxxxxxxxxxx>
- Date: Wed, 14 Mar 2007 18:25:34 +0200
I don't know. There must be a reason for this. MS does care of the
developers and if a feature is not there there should be a reason.
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Jerad Rose" <no@xxxxxxxx> wrote in message
news:O0%23dnRlZHHA.2448@xxxxxxxxxxxxxxxxxxxxxxx
Thansk again, Eliyahu.
This sounds like it might work as a workaround, but it's definitely not a
very elegant approach. So it sounds like there is no built-in method that
.NET supports? Is there a reason why this ability isn't there? Is it an
oversight, or is it a bug?
For example, to me, it would make much more sense if either:
a) the DataGrid Columns collection *was* populated with autogenerated
columns, instead of being completely empty
b) setting the ColumnMapping to Hidden *did* work
Is there any logical explanation as to why neither of these is the case?
Thanks again.
Jerad
"Eliyahu Goldin" <REMOVEALLCAPITALSeEgGoldDinN@xxxxxxxxxxxx> wrote in
message news:%23SXdq$gZHHA.4000@xxxxxxxxxxxxxxxxxxxxxxx
There is an easily solution to this. In the same ItemCreated event detectan
the Header item and locate in it's Cells collection the cell with the
text
matching your column name. Remember the order of this cell and use it as
index for data items.is
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Jerad Rose" <no@xxxxxxxx> wrote in message
news:uQeyGngZHHA.4872@xxxxxxxxxxxxxxxxxxxxxxx
Thanks again for your response, Eliyahu.
I mentioned this in my origninal post, but I prefer not to use this
method, as it requires that I use an ordinal reference and I feel this
nota poor practice, since it depends on the column order not changing. I
would like to find a solution that allows me to reference the column by
name, and then hide it.
Is this not possible with my situation?
Thanks.
Jerad
"Eliyahu Goldin" <REMOVEALLCAPITALSeEgGoldDinN@xxxxxxxxxxxx> wrote in
message news:%23JvMNdgZHHA.2448@xxxxxxxxxxxxxxxxxxxxxxx
In this event you should be able to locate the cell belonging to the
column
you want to hide. You can hide the column by hiding individual cells.
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
"Jerad Rose" <no@xxxxxxxx> wrote in message
news:uaKtVgeZHHA.588@xxxxxxxxxxxxxxxxxxxxxxx
Thanks for the response.This
Unfortunately, I don't see how I can use this event to hide a column.
event is fired when creating row items, not columns (it passes
DataGridItemEventArgs, same as the ItemDataBound event). I still do
theseem to have access to any sort of collection or object representing
event.column I want to hide.
Can you elaborate on how I can achieve this through this event?
Thanks again.
Jerad
"Eliyahu Goldin" <REMOVEALLCAPITALSeEgGoldDinN@xxxxxxxxxxxx> wrote in
message news:ebFrE8ZZHHA.4940@xxxxxxxxxxxxxxxxxxxxxxx
You can catch autocreated columns (an hide them) in ItemCreated
leaveThere
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Jerad Rose" <no@xxxxxxxx> wrote in message
news:ekVzaaZZHHA.1300@xxxxxxxxxxxxxxxxxxxxxxx
I am working with a DataGrid (ASP.NET 2.0) that is set to
AutoGenerateColumns="true". It is being populated from a DataSet.
is a column that I want to hide from the display, but I want to
butit
in the DataSet so that it can be referenced. However, all attempts
that
I've tried are failing.
The main method I see being used is this:
myColumn.ColumnMapping = MappingType.Hidden
However, this isn't working -- the column remains visible.
If I do this:
myDataTable.Columns.Remove("MyColumn")
Then the column is hidden, but of course, this removes it from the
dataset.
Of course, I can't hide the column after the DataGrid is bound,
because
the Columns collection isn't populated when using
AutoGenerateColumns="true" (the reason for this still baffles me,
isI've given up on figuring that one out).
I'm aware that I could hide each individual cell on ItemDataBound,
but
this requires referencing the cell through a numeric index, which
=a
poor practice, IMO (what if the order of the columns changes?).
Here is the full code block:
Dim myDataSet As DataSet = GetDataSet()
myDataSet.Tables("Table").Columns("MyColumn").ColumnMapping
MappingType.Hidden
DataGrid1.DataSource = myDataTable
DataGrid1.DataBind()
Is there not a way to hide a column for a DataGrid that is using
AutoGenerateColumns="true", by referencing the column by name?
Thanks in advance for your help.
Jerad
.
- References:
- Hiding DataGrid Columns when AutoGenerateColumns="true"
- From: Jerad Rose
- Re: Hiding DataGrid Columns when AutoGenerateColumns="true"
- From: Eliyahu Goldin
- Re: Hiding DataGrid Columns when AutoGenerateColumns="true"
- From: Jerad Rose
- Re: Hiding DataGrid Columns when AutoGenerateColumns="true"
- From: Eliyahu Goldin
- Re: Hiding DataGrid Columns when AutoGenerateColumns="true"
- From: Jerad Rose
- Re: Hiding DataGrid Columns when AutoGenerateColumns="true"
- From: Eliyahu Goldin
- Re: Hiding DataGrid Columns when AutoGenerateColumns="true"
- From: Jerad Rose
- Hiding DataGrid Columns when AutoGenerateColumns="true"
- Prev by Date: Re: Hiding DataGrid Columns when AutoGenerateColumns="true"
- Next by Date: Re: Hiding DataGrid Columns when AutoGenerateColumns="true"
- Previous by thread: Re: Hiding DataGrid Columns when AutoGenerateColumns="true"
- Index(es):
Relevant Pages
|