Re: Formatting date in listview

Tech-Archive recommends: Fix windows errors by optimizing your registry



Hi,

Use :

lvi.SubItems.Add(
((DateTime)drow["a-lastacteventdate"]).ToShortDateString());


--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation



"Lars Erik Nes" <LarsErikNes@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:A2810A41-86E0-4875-BC34-475277CACC0A@xxxxxxxxxxxxxxxx
Hi all.

I have a problem. I get all my data from a dataset (not mssql) and in that
dataset i have a table called "Activity". In this table i have a few date
fields. When i display the dataset "Activity" in a listview the date
fields
is displayed like : dd.mm.yy 00:00:00. How can i format this date. I do
not
want the time. Just the date.

In my dataset "activity" all date fields are formatted as: dd.mm.yyyy. Why
do i get the 00:00:00 ?? and how can i avoid it?

some code i use:


private void LoadActivityList(DataTable dtActivities)
{
//Sort the datatable
dtActivities.DefaultView.Sort = "a-stringactno";

//display datatable in listview
//Set the List to Detail View
lvActivities.View = View.Details;
lvActivities.FullRowSelect = true;
lvActivities.HideSelection = false;
lvActivities.MultiSelect = false;

//create columns to display
lvActivities.Columns.Add("Activity no.", 80,
HorizontalAlignment.Left);
lvActivities.Columns.Add("Description", 200,
HorizontalAlignment.Left);
lvActivities.Columns.Add("Status", 50,
HorizontalAlignment.Left);
// BUG: this date i want to display as dd.mm.yyyy
lvActivities.Columns.Add("Created", 80,
HorizontalAlignment.Left);
lvActivities.Columns.Add("Last event", 100,
HorizontalAlignment.Left);
lvActivities.Columns.Add("Contract", 0,
HorizontalAlignment.Left);
lvActivities.Columns.Add("Product", 0,
HorizontalAlignment.Left);

// Clear the ListView control
lvActivities.Items.Clear();

// Display items in the ListView control
for (int i = 0; i < dtActivities.Rows.Count; i++)
{
DataRow drow = dtActivities.Rows[i];

// Define the list items and get data from datatable
ListViewItem lvi = new
ListViewItem(drow["a-stringactno"].ToString());
lvi.SubItems.Add(drow["a-problem"].ToString());
lvi.SubItems.Add(drow["a-status"].ToString());
lvi.SubItems.Add(drow["a-regdate"].ToString());
lvi.SubItems.Add(drow["a-lastacteventdate"].ToString());
lvi.SubItems.Add(drow["a-contr1"].ToString());
lvi.SubItems.Add(drow["a-prodid"].ToString());

// Add the list items to the ListView
lvActivities.Items.Add(lvi);
}
this.lvActivities.Sorting = SortOrder.Ascending;
}



.



Relevant Pages

  • Re: Listview for realtime applications
    ... EventArgs e) ), null, null); ... add items and have the control just display them without flickering the ... display because it is redrawn for each item. ... item is added to the listview. ...
    (microsoft.public.dotnet.framework.windowsforms.controls)
  • Re: Data binding
    ... with 20 columns you should be using a Datagrid. ... ListView to display 19 subitems is no fun and ListBox won't ... writing a custom control to do this would not be terribly hard. ...
    (microsoft.public.pocketpc.developer)
  • Re: Listview for realtime applications
    ... You can control the updating of the ListView with BeginUpdate. ... I need to be able to add items and have the control just display them without flickering the display because it is redrawn for each item. ... Hence my reference to scrolling in my original post, the control can scroll down through items without flickering so there must be some way of adding items and using a similar rendering technique. ... private void flickerToolStripMenuItem_Click(object sender, EventArgs e) ...
    (microsoft.public.dotnet.framework.windowsforms.controls)
  • Re: Listview for realtime applications
    ... Therefore I cannot suspend updating and re-enable it while adding items, this is exactly what I do when using the listview in the manner you describe however it isn't applicable in this situation. ... I need to be able to add items and have the control just display them without flickering the display because it is redrawn for each item. ... Hence my reference to scrolling in my original post, the control can scroll down through items without flickering so there must be some way of adding items and using a similar rendering technique. ... private void flickerToolStripMenuItem_Click(object sender, EventArgs e) ...
    (microsoft.public.dotnet.framework.windowsforms.controls)
  • Listboxes and ListView visual problems
    ... fire up Visual Studio, create a Windows Form, drag a ListView onto the form, ... create two columns in the listview and then compile and run. ... Also, with the listbox, text isn't updating correctly. ... the text within the listbox doesn't display until I happen to ...
    (microsoft.public.dotnet.languages.csharp)