We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

CellStyleInfo.Tag null in row header cell?

Hi, I''ve set the .Tag property on a bound column to a custom object, I can get this object back in the cell click event, but only on non header cells. For a header cell, the .Tag value is null. Is this something to do with sorting? I''m using a GridDataBoundGrid. Is there a way of not losing the .Tag value? Cheers, Ed

1 Reply

AD Administrator Syncfusion Team January 29, 2004 02:53 AM

Yes, the sorting support in GridDataBoundGrid uses the Tag object to track what column is sorted and how it was sorted. As a work around, you could create a hashtable to hold your tag objects for the header row. You could use the column mapping name as the key. You can store this hashtable as the Tag in cell 0,0 which is unaffected by the sorting support. Then when you need the tags, access them though cell 0,0. Here are some snippets. //set up the hashtable Hashtable ht = new Hashtable(); for(int i = 1; i < this.grid.Model.ColCount; i++) { //save some object for each column with mapping name key //here we just store the original colindex string key = this.grid.Binder.InternalColumns[i-1].MappingName; object o = i; ht.Add(key, o); } // store the hashtable as the Tag in cell 0,0 this.grid[0,0].Tag = ht; //use the hashtable private void grid_CellClick(object sender, GridCellClickEventArgs e) { if(e.RowIndex == 0 && e.ColIndex > 0) { Hashtable ht = this.grid[0,0].Tag as Hashtable; if(ht != null) { int fieldNum = this.grid.Binder.ColIndexToField(e.ColIndex); string s = this.grid.Binder.InternalColumns[fieldNum].MappingName; object o = ht[s]; if(o != null) { Console.WriteLine("column header {0} clicked", o); } } } }

Loader.
Live Chat Icon For mobile
Up arrow icon