Visual Basic .NET Forums  
Click here to advertise with us

Go Back   Visual Basic .NET Forums > Components & Controls > Grids > Winforms Grids

Winforms Grids Discussion related to grid controls of all types for Winforms

VB.NET Forums Newsletter Signup:
Email address:


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-23-2009, 5:28 PM
VB.NET Forum Fanatic
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: May 2009
Posts: 111
Reputation: 14
gate7cy is on a distinguished programming path ahead
Default Remove time from Date column, Datagrid

In my application I have several datagrids databinded to various tables. Within these tables I use many times a date field. The database is made in access. At the beginning I had the date format on default as long date. When I saw that time was added I changed it to shortdate. Still I get the time in the various datagrids. How do I remove the time from the datagrid so no time is entered when I create a new field. Thanks for the replies
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 06-23-2009, 5:51 PM
VB.NET Forum Idol
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Feb 2008
Location: USA
Posts: 816
Reputation: 459
MattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond repute
Default

You should post DataGrid questions in the ASP.NET section.

Set the DataFormatString property for the bound column to {0:d} for short date format.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 06-23-2009, 7:21 PM
VB.NET Forum Fanatic
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: May 2009
Posts: 111
Reputation: 14
gate7cy is on a distinguished programming path ahead
Default

Kind of a newbie in vb.net. Please be patient with my questions. My application is in vb.net and the datagrids are in winforms. So why should I post it in asp.net. Is it the same in winforms (vb.net) as in asp.net? Setting the property as you said, how do I set it? I already done a search online for solutions and I found the same answer elsewhere but could not set this property. Thank you for the replies
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 06-23-2009, 7:45 PM
JohnH's Avatar
VB.NET Forum Moderator
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Dec 2005
Location: Norway
Age: 37
Posts: 10,173
Reputation: 1273
JohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond repute
Default

Try the DataGridView control instead, here you can select among various DateTime display formats in the columns DefaultCellStyle.
__________________
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 06-24-2009, 11:32 AM
VB.NET Forum Idol
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Feb 2008
Location: USA
Posts: 816
Reputation: 459
MattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond repute
Default

Oops I had that as GridView in my head somehow, sorry. Use JohnH's suggestion with the DataGridView.

To set it open the DataGridView Tasks (little arrow in upper right corner)
Click Edit Columns
Select your column and click on the Defaul Cell Style property
Set the Format property to 'd'
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 06-24-2009, 4:52 PM
VB.NET Forum Fanatic
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: May 2009
Posts: 111
Reputation: 14
gate7cy is on a distinguished programming path ahead
Default

Thanks all for the replies. This worked just fine.I am trying to refresh the datagrid using parameter queries. I am filtering the grid using the date column. But I always get an empty grid. Here is the code.

Code:
    Private Sub DateTimePicker1_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged
        Dim dd As DateTime = CDate(CStr(Me.DateTimePicker1.Value))
        Me.TextBox1.Text = dd.ToString("mm/dd/yyyy")
        dd = CDate(Me.TextBox1.Text)


        Me.ServicesTableAdapter.testdate(Me.Database2DataSet.Services, dd)



    End Sub
thanks for the replies
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 06-24-2009, 5:42 PM
VB.NET Forum Idol
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Feb 2008
Location: USA
Posts: 816
Reputation: 459
MattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond repute
Default

mm/dd/yyyy should be MM/dd/yyyy

What happens when you try this?:

Code:
Me.ServicesTableAdapter.testdate(Me.Database2DataSet.Services, CDate(Me.DateTimePicker1.Value.ToString("MM/dd/yyyy"))
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 06-25-2009, 5:19 AM
VB.NET Forum Fanatic
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: May 2009
Posts: 111
Reputation: 14
gate7cy is on a distinguished programming path ahead
Default

I get this error:

"Conversion from string "06/18/2009" to type 'Date' is not valid."
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 06-25-2009, 7:04 AM
JohnH's Avatar
VB.NET Forum Moderator
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Dec 2005
Location: Norway
Age: 37
Posts: 10,173
Reputation: 1273
JohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond repute
Default

Why would you convert DTP.Value anyway? It already returns a Date value, the return type is DateTime which is a Date.

Note that time is always a part of the Date value, if you want to reset the time part to 0 (midnight) you can use the Date property; DTP.Value.Date.

Since you query items with a single Date parameter you also have to make sure the Date values in your database is normalized to time 0 in a similar fashion, else you will find no records because the time part of the Date value would differ. If this is not possible you have to query a Date range that includes any time of that day.
__________________
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 06-25-2009, 7:18 AM
VB.NET Forum Fanatic
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: May 2009
Posts: 111
Reputation: 14
gate7cy is on a distinguished programming path ahead
Default

Strict On forces me to change it. How do I normalise my time in the database to midnight for all entries? How can I do it for the allready included entries and how will I do it in vb for the new entries. Thanks for the help. You are helping alot guys. Sorry though for the many questions
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





All times are GMT -4. The time now is 12:17 PM.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2


For advertising opportunities click here.