Hi,
Sorry, based on my understanding, you can do like this:
Hashtable ht=new Hashtable();
ht.Add("Balance ",7);
DataGrid1.Colum ns[(int)ht["Balance"]].Visible=false;
I think this is equivalent to DataGrid1.Colum ns[7].Visible=false;
If I still misunderstandin g 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+toVC8 AQIKSMcrk0va2dQ ==
| X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
| From: "=?Utf-8?B?TWF0dA==?=" <an*******@disc ussions.microso ft.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************ *************** *******@microso ft.com>
| 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.publi c.dotnet.langua ges.csharp
| NNTP-Posting-Host: TK2MSFTCMTY1 10.40.1.180
| Path: cpmsftngxa06.ph x.gbl!cpmsftngx a10.phx.gbl
| Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.csharp:1992 84
| X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.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 DataGridCollect ion).
I've created a new property to by class myDataGrid:
private myNamespace.Dat aGridColumnColl ection _dataGridColumn Collection;
/// <summary>
/// Gets columns by their key attribute.
/// </summary>
public virtual System.Web.UI.W ebControls.Data GridColumnColle ction
ColumnsByKey
{
get
{
if (_dataGridColum nCollection == null)
{
_dataGridColumn Collection = new myNamespace.Dat aGridColumnColl ection();
_dataGridColumn Collection.Colu mnSource = Columns;
}
return _dataGridColumn Collection;
}
}
And the (proxy) collection class:
/// <summary>
/// myNamespace.Dat aGridColumnColl ection.
/// </summary>
public class DataGridColumnC ollection //: IEnumerable - removed to display
less code.
{
private System.Web.UI.W ebControls.Data GridColumnColle ction _columnSource;
public DataGridColumnC ollection()
{
}
protected internal System.Web.UI.W ebControls.Data GridColumnColle ction
ColumnSource
{
get {return _columnSource;}
set {_columnSource = value;}
}
public System.Web.UI.W ebControls.Data GridColumn this[string Key]
{
get
{
for (int i=0; i<_columnSource .Count; i++)
if (((IVPGridColum n)_columnSource[i]).Key == Key)
return _columnSource[i];
return null;
}
}
}
Now I have 2 properties for my DataGrid which return the same collection:
"Columns" and "ColumnsByK ey".
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.W ebControls.Data GridColumnColle ction.
Is it possible to do this?
I hope this makes sense.
TIA,
Matt.
|