Hi,
My grid has a column on which if the the column cell has null value i want to show some text depending on flag e.g. My grid has column1, column2, column3. Grid has 4 records of which two has null value for column1.
I want to show if column1 cell has null value and flag = true (this flag value is getting from the data source which i bound to the ultragrid ) then show cell value = 'Completed (Some status)' or
if column1 cell has null value and flag = false then show cell value = "N/A"
How can I achieve this, I unable to decide on which event I have to write the code. May be cell related event will be helpful so that I can set the value.
Thanks & Regards,
Pramod Pawar
Hi Pramod,
It's not clear to me where you want the text to display. It would be difficult to show text in a cell whose value is null without changing the value of that cell to a string.
What I would do is hide the column that contains the real data and then add an unbound column to the grid which can display the text or not depending on the value in the real column.
You would do hide the real column and add the unbound column in the grid's InitializeLayout event.
Then you would use the InitializeRow event to examine the value in the real hidden column and set the Value on the unbound column cell to whatever you want.
Thanks Mike for your instant reply.
Actually, I just want manupulate with the cell value and then need to display on the grid.
Say, Column1.nullText ='some text' will set the text wherever we have null value. But, for some reason, I want to do write some business logic if there is null value. Hence, Column1.nullText will not work in this case.
How do I change cell data if I want to set some logic for it.
Well, if you want to set the actual value of the cell from null to a string, the best place to do that is in the InitializeRow event. This event fires when the row is created and also any time a value in any cell of that row changes.
You can examine the value of any cell(s) in that row using:
e.Row.Cells["column key"].Value (or Text)
And then you can set the Value on the cell you want to whatever you choose.
If your external variable changes and you want the grid to refresh the rows then you can call:
grid.Rows.Refresh(FireInitializeRow)
This will re-fire the InitializeRow event for every row.
Yeah..I tried this. But, it only allows e.Row.Cells["column key"].Value and not able to set
e.Row.Cells["column key"].Text - (Getting error read only property cant assigned). And value is getting bound from DataColumn. And Datatype of this bound column is DateTime, hence its not allowing me to set string value to this column. So, unable to set e.Row.Cells["column key"].Value.
Is there any way to set e.Row.Cells["column key"].Text . If so, I can set the string value to that. It will solve my issue.
thanks
You cannot set the Text of a cell, only the Value can be set. And the Value will always write to the DataSource.
That's why I suggested using an unbound column, but you said you were okay with updating the actual data.
If you cannot actually change the value in the data source to the text you want, then you will have to use the unbound column approach I described above.
Allright....thanks a lot..will try with unbound column then.. but why do we have text as a read only..
Can't I submit to have feature to assgin a text. Cause, binidng with unbound column will be disturbing the existing layout or existing framework issues.
Thanks,
No issues Mike.. Unbound column solves my problems... Only concern was with our existing framework. Either way, I need to modify the logic, so better to go with Unbound column :)
Thanks anyways for your great Direction.
You cannot set the Text because the text is generated from the Value and accounts for things like Format and Masking on the column. It also accounts for a ValueList which converts a DataValue into matching DisplayText.
If you don't want to use an unbound column, then you have some other options. You could use a DataFilter and an editor. But this is more complicated than using an unbound column and it requires you to handle the conversion in both directions.: DisplayText to DataValue and vice versa.