This is a migrated thread and some comments may be shown as answers.

Column Custom Object

1 Answer 126 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Bill
Top achievements
Rank 1
Bill asked on 14 May 2009, 05:24 PM
Is there a way for an bound grid with an unbound column to contain a custom object such as a Hashtable?  If so, how would it be implemented?

Thanks

1 Answer, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 15 May 2009, 09:21 AM
Hello Bill,

Yes, this is possible. However, I am not sure that this is the best option. Hashtable(s) require large amounts of memory and when using them in a grid with a lot of rows you could easily run out of memory.

To create an unbound column which data type is hashtable follow these steps:

1. Create a new column and set its DataType property to Hashtable
2. Use the Value property of GridViewCellInfo to set the value
3. Handle CellFormatting event to display the value

And here is the code:

// Create the columm 
GridViewDataColumn column = new GridViewDataColumn("Hashtable"""); 
column.DataType = typeof(Hashtable); 
this.radGridView1.Columns.Add(column); 
 
// Set a value 
Hashtable ht = new Hashtable(); 
ht["text"] = "124"
this.radGridView1.Rows[1].Cells["Hashtable"].Value = ht; 

void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e) 
    GridDataCellElement cell = e.CellElement as GridDataCellElement; 
    if (cell != null && cell.ColumnInfo.HeaderText == "Hashtable"
    { 
        Hashtable table = cell.Value as Hashtable; 
        if (table != null && table.ContainsKey("text")) 
        { 
            cell.Text = (string)table["text"]; 
        } 
        else 
        { 
            cell.Text = "empty"
        } 
    } 

Please share more details on the exact scenario and I will try to find a better option. I am looking forward to your reply.

All the best,
Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
GridView
Asked by
Bill
Top achievements
Rank 1
Answers by
Jack
Telerik team
Share this question
or