Hi,
Sorry, based on my understanding, you can do like this:
Hashtable ht=new Hashtable();
ht.Add("Balance",7);
DataGrid1.Columns[(int)ht["Balance"]].Visible=false;
I think this is equivalent to DataGrid1.Columns[7].Visible=false;
If I still misunderstanding you, please feel free to let me know.
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! -
www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
--------------------
| Thread-Topic: Extending a Collection indexer
| thread-index: AcOql52oJ+toVC8AQIKSMcrk0va2dQ==
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
| From: "=?Utf-8?B?TWF0dA==?=" <an*******@discussions.microsoft.com>
| References: <O1**************@TK2MSFTNGP11.phx.gbl>
<ry**************@cpmsftngxa06.phx.gbl>
| Subject: RE: Extending a Collection indexer
| Date: Fri, 14 Nov 2003 02:11:06 -0800
| Lines: 75
| Message-ID: <74**********************************@microsoft.co m>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: TK2MSFTCMTY1 10.40.1.180
| Path: cpmsftngxa06.phx.gbl!cpmsftngxa10.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:199284
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| Hi Jeffrey,
Thanks for your response, but I don't fully understand what you imply.
I could create a new Hashtable property with the string/value pairs, but
his is no different really from just using int constants.
What I'm trying to acheive is to be able to extend the current "Columns"
property (of type DataGridCollection).
I've created a new property to by class myDataGrid:
private myNamespace.DataGridColumnCollection _dataGridColumnCollection;
/// <summary>
/// Gets columns by their key attribute.
/// </summary>
public virtual System.Web.UI.WebControls.DataGridColumnCollection
ColumnsByKey
{
get
{
if (_dataGridColumnCollection == null)
{
_dataGridColumnCollection = new myNamespace.DataGridColumnCollection();
_dataGridColumnCollection.ColumnSource = Columns;
}
return _dataGridColumnCollection;
}
}
And the (proxy) collection class:
/// <summary>
/// myNamespace.DataGridColumnCollection.
/// </summary>
public class DataGridColumnCollection //: IEnumerable - removed to display
less code.
{
private System.Web.UI.WebControls.DataGridColumnCollection _columnSource;
public DataGridColumnCollection()
{
}
protected internal System.Web.UI.WebControls.DataGridColumnCollection
ColumnSource
{
get {return _columnSource;}
set {_columnSource = value;}
}
public System.Web.UI.WebControls.DataGridColumn this[string Key]
{
get
{
for (int i=0; i<_columnSource.Count; i++)
if (((IVPGridColumn)_columnSource[i]).Key == Key)
return _columnSource[i];
return null;
}
}
}
Now I have 2 properties for my DataGrid which return the same collection:
"Columns" and "ColumnsByKey".
What I really want is to extend the orignal property "Columns" by creating
a property this[string Key] for it. However I can't derive from
System.Web.UI.WebControls.DataGridColumnCollection .
Is it possible to do this?
I hope this makes sense.
TIA,
Matt.
|