Re: Hiding DataGrid Columns when AutoGenerateColumns="true"



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 detect
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
an
index for data items.

--
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
is
a 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.

Unfortunately, I don't see how I can use this event to hide a column.
This
event is fired when creating row items, not columns (it passes
DataGridItemEventArgs, same as the ItemDataBound event). I still do
not
seem to have access to any sort of collection or object representing
the
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
event.

--
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.
There
is a column that I want to hide from the display, but I want to
leave
it
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,
but
I'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
is
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















.



Relevant Pages

  • Re: Getting cell index from cell to the right
    ... The reason why I have constructed the data list as I have is that I want it ... "RagDyer" wrote: ... I couldn't get your option with setting a reference to work. ... I gave the cell a name and set it to refer to the cell to the right ...
    (microsoft.public.excel.misc)
  • Re: Formula changes when adding rows
    ... Thanks for the reply....the reason I use the "Address" option is so ... If I do it as you suggest then the cell reference will always be K108. ... As for the row changing, the function is referencing another sheet, so ...
    (microsoft.public.excel)
  • Re: Conditional format with error & date check
    ... For some reason I had wrongly been thinking that if I referenced a single ... cell instead of a range it wouldn't apply the format to the range I had ... Click the format button ... I'm sure I could use a specific cell reference such ...
    (microsoft.public.excel.worksheet.functions)
  • Re: Excel
    ... The reference in the formula does not change ... automatically after line insertion? ... One possible reason is that how to cell address is referred in your formula. ...
    (microsoft.public.excel.worksheet.functions)
  • Re: C# or VB.NET?
    ... i am a part-time/casual developer. ... VBScript, and now when I'm migrating to .NET, I obviously chose VB.NET. ... The reason, of course, is the .NET Framework... ... The reason that both languages are identical is because they both target the .NET Framework. ...
    (microsoft.public.dotnet.framework.aspnet)

Quantcast