473,324 Members | 2,581 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Formatting date in listview

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;
}

Jun 6 '06 #1
2 6685
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" <La*********@discussions.microsoft.com> wrote in message
news:A2**********************************@microsof t.com...
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;
}

Jun 6 '06 #2
Hi.

Thank you for your reply. I get a run-time error.

Message "the specified cast is not valid". What can be wrong. I can see that
my datatabel "dtActivities" contains a date in the field "a-lastactevetndate"
(18.06.2006 00:00:00)

Any more tips`?

Thanks.

Lars E.

"Ignacio Machin ( .NET/ C# MVP )" wrote:
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" <La*********@discussions.microsoft.com> wrote in message
news:A2**********************************@microsof t.com...
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;
}


Jun 7 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jouke Langhout | last post by:
Hello all! For quite some time now, I've got the following problem: Access won't close properly when a user closes the application. An ACCESS process stays active and that process can only be...
2
by: Sara | last post by:
The problem: Conditional formatting bold, red when field Value < date() sets the field background to white - always - whether condition is met or not. I want the field unfilled and just red/bold...
4
by: deko | last post by:
I've heard it's best not to have any formatting specified for Table fields (except perhaps Currency), and instead set the formatting in the Form or Report. But what about Yes/No fields? When I...
4
by: hope | last post by:
Hi, How can I format a string field using Data Formatting Expression property in datagrid? For example: format last name from BROWN to Brown. Thanks
4
by: Nalaka | last post by:
Hi, I have two questions about gridViews. 1. How can I intercept the row/column values at loading to change values? 2. After I update a row (using default update functionality), how can I...
2
by: johndcal | last post by:
Hello All, I have a date value that I pull from a .csv file. After reading the file and storing the values in an array the value of the date could be found in $array, for example....
2
by: David Veeneman | last post by:
How does one format a date column in a GridView control? I had assumed that the DataFormat string would do it, but MSDN only shows numeric formatting codes. Can dates be formatted using that...
4
by: Ken Wigle | last post by:
All, I would be very grateful for any help on this question. I have an application in asp.net 2.0 where I dynamically create a datatable and then bind that to a gridview. Unfortunately, the...
6
by: Tomasz J | last post by:
Hello developers, I bind my TextBox control specyfying a format stored in my application global ApplicationContext object - it has a static string CurrencyFormat property. The problem - this...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.