Javier Gonzalez de Aragon
Top achievements
Rank 2
Javier Gonzalez de Aragon
asked on 13 Mar 2012, 09:32 PM
Is it possible to format a column using number formats or date formats?
Thanks,
Javier Gonzalez de Aragon
Thanks,
Javier Gonzalez de Aragon
4 Answers, 1 is accepted
0
Richard Slade
Top achievements
Rank 2
answered on 14 Mar 2012, 03:13 PM
Hi Javier,
Have a look at the help topic on data formatting which should give you the answers.
If you need further help though, then just let me know
Richard
Have a look at the help topic on data formatting which should give you the answers.
If you need further help though, then just let me know
Richard
0
Javier Gonzalez de Aragon
Top achievements
Rank 2
answered on 14 Mar 2012, 09:33 PM
That help topic refers to GridView and I need to format columns in ListView. Does it apply as well?
Thanks,
Javier Gonzalez de Aragon
Thanks,
Javier Gonzalez de Aragon
0
Richard Slade
Top achievements
Rank 2
answered on 15 Mar 2012, 10:48 AM
Hi Javier,
My apologies for giving you a link to the incorrect topic.
You can't pass a list view column a format, but you could subscribe (for exmaple) to the VisualItemFOrmatting event to format the text
There may be other ways too depending on your requirements. Let me know if you need more information though
Richard
My apologies for giving you a link to the incorrect topic.
You can't pass a list view column a format, but you could subscribe (for exmaple) to the VisualItemFOrmatting event to format the text
this
.radListView1.VisualItemFormatting +=
new
ListViewVisualItemEventHandler(radListView1_VisualItemFormatting);
void
radListView1_VisualItemFormatting(
object
sender, ListViewVisualItemEventArgs e)
{
}
There may be other ways too depending on your requirements. Let me know if you need more information though
Richard
0
Accepted
Hi Javier,
Richard's suggestion will work in SimpleView and IconView since the items in these two views are simple. However, the visual items in DetailView are complex and contain a number of cells, each with a different value. Therefore, to format the data in cells that belong to a given column, you should use the CellFormatting event. The following code snippet demonstrates how you can format the values of type DateTime in the second column:
I hope this will help you. Feel free to ask if you have any further questions.
Regards,
Ivan Todorov
the Telerik team
Richard's suggestion will work in SimpleView and IconView since the items in these two views are simple. However, the visual items in DetailView are complex and contain a number of cells, each with a different value. Therefore, to format the data in cells that belong to a given column, you should use the CellFormatting event. The following code snippet demonstrates how you can format the values of type DateTime in the second column:
public
partial
class
Form1 : RadForm
{
public
Form1()
{
InitializeComponent();
this
.radListView1.Columns.Add(
"Column1"
);
this
.radListView1.Columns.Add(
"Column2"
);
this
.radListView1.ViewType = ListViewType.DetailsView;
for
(
int
i = 0; i <= 100; i++)
{
this
.radListView1.Items.Add(
"Item "
+ i, DateTime.Now.AddHours(i));
}
this
.radListView1.CellFormatting +=
new
ListViewCellFormattingEventHandler(radListView1_CellFormatting);
}
void
radListView1_CellFormatting(
object
sender, ListViewCellFormattingEventArgs e)
{
DetailListViewDataCellElement dataCell = e.CellElement
as
DetailListViewDataCellElement;
if
(dataCell !=
null
&& dataCell.Data ==
this
.radListView1.Columns[1])
{
dataCell.Text = ((DateTime)dataCell.Row[1]).ToShortTimeString();
}
}
}
I hope this will help you. Feel free to ask if you have any further questions.
Regards,
Ivan Todorov
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>