The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
|
|
Datagrid column formatting
Posted: 12 Nov 09 9:57 AM
|
I have a form with a datagrid. Every column in the datagrid in databound. The first column is an encoded ID field. The column name is Date. What I want to do is after the column or row has been databound, I want to convert the 0th column to an acutal date from our encoded ID.
Iam in the middle of exploring the idea of converting the column to a Custom Format column, data bound to the ID field then write a code snipet under 'Format Code'
is this the best way? |
|
|
| |
| |
|
Re: Datagrid column formatting
Posted: 13 Nov 09 12:04 PM
|
so i wrote a snippet for the custom column, like your article shows....
but i get a 'object reference not set to an instance of an object' error with this code...
protected string ConvertBlastIDToDate(object name) { string strID = (string)name; strID = strID.Substring(strID.Length - 12); FormatProvider TimeFormat = new Globalization.CultureInfo(""); DateTime dt = DateTime.ParseExact(strID, "yyMMddHHmmss", TimeFormat); }
im sure the error is caused from the (string) cast... what is object really? is it the column class? is it the data that will be bound to the column ?
|
|
|
|
Re: Datagrid column formatting
Posted: 13 Nov 09 12:38 PM
|
Using it as a string should be fine if your value is a string type. However, it might be a good idea to check for null as well
if (name != null) { //... }
If you look at how it looks on a deployed smartpart it might make more sense. IIRC it takes the bound object (not a column object, but the property being bound) and just passes it to the method. |
|
|
|