|
Hello everyone,
I've got a datagridview in a control which i populate programmatically using values retrieved from a database. Mostly it is fine, however when I set the vale of the cell to be a date i.e "2010-06-10" it transforms it into "10/06/2010 00:00:00". Oh and the type on the database is date...I'm guessing this is what vb is using as the cells format....
I don't mind the date switching around but the addition of the 00:00:00 looks stupid. I know it's probably very simple but I can't find the solution anywhere.
thanks in advance
Chris
modified on Friday, June 11, 2010 11:11 AM
|
|
|
|
|
How are you populating the DataGrid? Are you using a DataSet, DataTable or are you populating manually with a DataReader ? The answer to that question would enable someone to answer properly.
|
|
|
|
|
Hi,
sorry I'm doing it manually using a datareader:
While drgetcusfile.Read()
Dim count As Integer = fieldnostart
Dim rowcount As Integer = 0
grid.Columns.Add("Property", "Property")
grid.Columns.Add("Value", "Value")
While count <= fieldnoend
grid.Rows.Add()
grid.Item(0, rowcount).Value = rows(rowcount)
grid.Item(1, rowcount).Value = drgetcusfile.Item(count)
count += 1
rowcount += 1
End While
the datareader returns 1 row of various different types of data.
thanks,
Chris
|
|
|
|
|
I think in that case you will need to specifically test whether the value is a date using something like this :
While count <= fieldnoend
grid.Rows.Add()
grid.Item(0, rowcount).Value = rows(rowcount)
if drgetcustfile.Item(count).GetType.ToString = "System.DateTime" Then
grid.Item(1, rowcount).Value = Format(drgetcusfile.Item(count),"short date")
Else
grid.Item(1, rowcount).Value = drgetcusfile.Item(count)
End If
End While
This is just off the top of my head. Hope it Helps
Happy Coding
|
|
|
|
|
hi,
thanks for that, I think it would work.....
I figured another way around it when you asked about the method i was using to get the data:
While count <= fieldnoend
grid.Rows.Add()
grid.Item(0, rowcount).Value = rows(rowcount)
Try
grid.Item(1, rowcount).Value = drgetcusfile.GetString(count)
grid.Item(1, rowcount).Value = DateTime.ParseExact(grid.Item(1, rowcount).Value, "yyyy-MM-dd", Nothing).ToShortDateString()
Catch ex As Exception
End Try
count += 1
rowcount += 1
End While
the Datareader.GetString method is what I was looking for to get the exact string on the database, so I can try to parse it into a decent looking date.
Chris
|
|
|
|
|
I disagree with the approach you seem to have taken.
In a database dates and times should be stored in a specialized field type, and not as a string; strings will always lead to confusion, and make for difficult queries. It is the GUI that should take care of formatting, i.e. convert values (datetimes, numbers, whatever) to strings in the way the user wants them to be.
Hence, DateTime field in the database, and an appropriate format for each of the DGV columns.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
The OP has obviously got all his SQL and everything bundled in the UI. While WE know that approach is all wrong, I know if I look back to when I started, my apps were pretty much also unreadaable and unmaintainble, if I look back at them now.
|
|
|
|
|
I can understand that, but can't approve it, so I felt a need to state so. What the OP does is up to him; he may or may not remember (and understand) my comment at some future occasion.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
yep your right,
all the sql for each of the controls is hard coded into the custom control. I possibly could bundle the sql into the databse (we're using Solid....ever heard of it?) however this has never been done in the application before and it's a 13 year habit I don't want to break. As Uniface, the other platform we have used since 1990, retrieves the data in such an efficiant manner in it's own weird way, starting to add queries into the database now doesn't make sense to us for few a tiny and simple query screens. Where else would you put the sql?
The data is stored in date type fields on the database so i shouldn't really get the string value I guess....
BTW, what is a OP?
Chris
oh and I tried
grid.Columns(0).DefaultCellStyle.Format = "dd/MM/yyyy"
but when the column is used for a actual string value, i.e an order number, I just get dd/MM/yyy although the date is converted properly
Turns out they needed to be date type cells for sorting so used this:
grid.Item(1, rowcount).Value = drgetcusfile.Item(count)
If grid.Item(1, rowcount).Value.GetType.Equals(GetType(Date)) Then
grid.Item(1, rowcount).Style.Format = "dd/MM/yyyy"
End If
:
|
|
|
|
|
It sounds to me as if it is not your typical n-Tier .Net app, and it has been working like that for so many years, why change it ? It may not live up to todays so-called standards, but I've been in this game for too long not to say things won't completely do a 180 degree turnaround in 5 years time.
|
|
|
|
|
private void Form1_Load(object sender, EventArgs e)
{
DataTable datatable = new DataTable();
datatable.Columns.Add("col1",typeof(DateTime));
datatable.Columns.Add("col2", typeof(DateTime));
datatable.Rows.Add(DateTime.Parse("2007/12/31 5:00:11 PM"), DateTime.Parse("2008/01/01 6:00:12 AM"));
datatable.Rows.Add(DateTime.Parse("2007/4/4 1:00:13 AM"), DateTime.Parse("2007/8/8 3:00:14 PM"));
dataGridView1.DataSource = datatable;
dataGridView1.Columns[0].DefaultCellStyle.Format = "dd'/'MM'/'yyyy";
dataGridView1.Columns[1].DefaultCellStyle.Format = "dd'/'MM'/'yyyy hh:mm:ss tt";
}
|
|
|
|
|
oops , just realised this a vb forum... but you get the idea.
|
|
|
|
|
In a DataGridView you can set the default formatting style for each individual column; a statement similar to this C# one would suffice
dgv.Columns[columnNumber].DefaultCellStyle.Format="dd MMM yyyy";
FWIW: You can also set the style for each individual cell, and you can wire a handler to an event that fires whenever any cell needs formatting. So everything is possible!
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
I have a splitcontainer on my form.
Panel1 has my menu and panel2 holds the WindowForms.
If I click on my menu in panel 1 it should check if a form is loaded in panel2.If there is a form, then it closes it.
Thanks for everyones help
|
|
|
|
|
hi,
if you only have one form you can make the form global to access it by click on menu item..
if you have more than one form on the panel2 you need to interate through the ControlsCollection of Panel2 to determinate if one of the controls is a Form or not.
greetz
|
|
|
|
|
Thank you for your respond
It will always be one form, but I need the form name or id to close it
and I dont want to hardcode the forms name.
I want basically: Is there a form open, if there is retrieve its id and then say id.close
|
|
|
|
|
What I would do is in your main form I would create a form lavel variable that returns a form i.e
Private OpenForm as Form . I would assign this to the current form that is opened in the procedure that opens the form, and in the procedure that checks if a form is open you can just do this
If Not OpenForm Is Nothing Then
Else
OpenForm.Close
End If
Hope this helps
Happy Coding
|
|
|
|
|
Brilliant, thank you it's working just the way I wanted it to work.
|
|
|
|
|
Pleasure, glad it helped.
Just be sure to make sure you set the OpenForm variable to nothing when the form is closed, else this will not work the second time.
Happy Coding
|
|
|
|
|
Hi, dear all,
I don't know if this is the right place for my post.
I have to projects ( we called them as A and B) created using VB6. A is created several years ago and already formally distributed. Now I create the project B based on project A, they are almost same except some interface and the two project belong to different owners. Since the functionality of these two project are same, so they have some dependency files are also same.
My problem is that if I install only one from the two project, no problem. If I install two project, then uninstall one, the other one doesn't work. it give message like "one of the dependency not correctly registered,.....
Somebody suggests me to use merge module to solve this issue. do you think my case is good to use merge module? if we need to use merge module, do these two project's installation setup file will be recreated to include the merge module to them?
Or you have any good idea? thanks a lot.
|
|
|
|
|
The shared resources (assemblies, activeX controls etc) could indeed be tucked away in their own installation package. Now, it would get confusing if you were to create three setups. It's kinda like having the problem of distributing Sql Express along with your product.
A merge-module would become a part of the installation, similar to other 'prerequisites'. A good place to start is MSDN[^].
I are Troll
|
|
|
|
|
Eddy,
Thanks for your reply.
|
|
|
|
|
Hello, I realize this isn't directly related to VB but I hope someone can help.
I created a WCF windows service that's listening on port 52799. When the service is started as a system user - it listens and other PC's can log into the service without issue. When I try to change the user from system to a domain user (admin to the server where the service is running) and start the service using their crudentials, the service no longer appears to be listening and other PC's timeout attempting connect.
I have added the security permission.demand/assert logic to the service and no change. Can someone help me figure out what a non-system user doesn't work as expected?
Thank you for your time.
Nathan
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous
'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous
|
|
|
|
|
nlarson11 wrote: I realize this isn't directly related to VB
So why post it in the VB forum rather than the WCF forum?
It's time for a new signature.
|
|
|
|
|
nlarson11 wrote: nlarson11 has posted a reply to your message at "Visual Basic":
Hey Rich,
I feel like such and ass inconveniencing you where you had to waste your time reading my misplaced question. May you be on the receiving end of your attitude when you need help.
Thanks again.
Yeah sorry, I see that you are a reasonably long-standing member of CP so you obviously don't need advice from the likes of me.
It's time for a new signature.
|
|
|
|