472,139 Members | 1,643 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

datagrids..... i just cant get them to do what i want

Below is my code that is carried out on my dataset, datagrid etc...

Im trying to get column0 "Date & Time" to show date and time, not just date

ive read some stuff posted by Dmitriy Lapshin on this board that goes way
over my
ability (this is my first vb or vb.net project). from what I can tell i
need a GridColumnStyles
collection adding to my datagrid but each and everytime I try to do this my
code crashes.

It seems such a simple problem that is taking way too long to try and sort,
so any help would be greatly appreciated

Regards
Mike Fellows

da.SelectCommand = New OleDbCommand(SQLStr, ocon)
'Fill the DataSet with the Data
da.Fill(ds)

ds.Tables(0).Columns.Item(0).ColumnName = "Date & Time"
ds.Tables(0).Columns.Item(1).ColumnName = "Call Made By"
ds.Tables(0).Columns.Item(2).ColumnName = "Days Since RTB"
ds.Tables(0).Columns.Item(3).ColumnName = "Action"
ds.Tables(0).Columns.Item(4).ColumnName = "Price In"
ds.Tables(0).Columns.Item(5).ColumnName = "Property Valued"
ds.Tables(0).Columns.Item(6).ColumnName = "Notes"

Dim ts As New DataGridTableStyle()
ts.MappingName = "Table"

DataGrid1.TableStyles.Clear()
DataGrid1.TableStyles.Add(ts)
Me.DataGrid1.DataSource = ds.Tables(0)
ts.GridColumnStyles(0).Width = 90
ts.GridColumnStyles(1).Width = 90
ts.GridColumnStyles(2).Width = 100
ts.GridColumnStyles(3).Width = 90
ts.GridColumnStyles(4).Width = 90
ts.GridColumnStyles(5).Width = 90
ts.GridColumnStyles(6).Width = 250
RowCount = ds.Tables(0).Rows.Count
ColumnCount = ds.Tables(0).Columns.Count
da.Dispose()
ds.Dispose()
ocon.Close()
ocon.Dispose()
Nov 20 '05 #1
7 1349
First of all never say your code "crashes". It says nothing about the
problem. Always use a Try Catch block to trap the error and report that.

Dates and times throw many beginners for a loop.

i suspect the problem is with your database setup. See the ADO.NET ng about
that. If you are using an access database the simple Date/Time field will do
what you want. The "General" under format will work nicely.

But lets say you were filling a textbox with a date/time setup and it was
not the way you wanted it:

TextBox7.Text = Format(Date.Now, "MM/dd/yyyy HH:mm:ss")

or

Textbox7.Text = Format(Dsjobitems1.Tables(0).Rows(0).Item("MYDATE" ),
"MM/dd/yyyy")

hope this helps.......


"Mike Fellows" <mi*************@equityhouse.co.uk.SPAM> wrote in message
news:sm******************@newsfep2-gui.server.ntli.net...
Below is my code that is carried out on my dataset, datagrid etc...

Im trying to get column0 "Date & Time" to show date and time, not just date
ive read some stuff posted by Dmitriy Lapshin on this board that goes way
over my
ability (this is my first vb or vb.net project). from what I can tell i
need a GridColumnStyles
collection adding to my datagrid but each and everytime I try to do this my code crashes.

It seems such a simple problem that is taking way too long to try and sort, so any help would be greatly appreciated

Regards
Mike Fellows

da.SelectCommand = New OleDbCommand(SQLStr, ocon)
'Fill the DataSet with the Data
da.Fill(ds)

ds.Tables(0).Columns.Item(0).ColumnName = "Date & Time"
ds.Tables(0).Columns.Item(1).ColumnName = "Call Made By"
ds.Tables(0).Columns.Item(2).ColumnName = "Days Since RTB"
ds.Tables(0).Columns.Item(3).ColumnName = "Action"
ds.Tables(0).Columns.Item(4).ColumnName = "Price In"
ds.Tables(0).Columns.Item(5).ColumnName = "Property Valued"
ds.Tables(0).Columns.Item(6).ColumnName = "Notes"

Dim ts As New DataGridTableStyle()
ts.MappingName = "Table"

DataGrid1.TableStyles.Clear()
DataGrid1.TableStyles.Add(ts)
Me.DataGrid1.DataSource = ds.Tables(0)
ts.GridColumnStyles(0).Width = 90
ts.GridColumnStyles(1).Width = 90
ts.GridColumnStyles(2).Width = 100
ts.GridColumnStyles(3).Width = 90
ts.GridColumnStyles(4).Width = 90
ts.GridColumnStyles(5).Width = 90
ts.GridColumnStyles(6).Width = 250
RowCount = ds.Tables(0).Rows.Count
ColumnCount = ds.Tables(0).Columns.Count
da.Dispose()
ds.Dispose()
ocon.Close()
ocon.Dispose()

Nov 20 '05 #2
Hi Mike,

Some observations on your code:

a) Never assign grid's DataSource property directly. Use the
SetDataBinding() method instead.
b) The table style/column style setup should always be done BEFORE the data
source is bound to the grid.
c) Mind this caution from MSDN Library:

CAUTION Always create DataGridColumnStyle objects and add them to the
GridColumnStylesCollection before adding DataGridTableStyle objects to the
GridTableStylesCollection. When you add an empty DataGridTableStyle to the
collection, DataGridColumnStyle objects are automatically generated for you.
Consequently, an exception will be thrown if you try to add new
DataGridColumnStyle objects with duplicate MappingName values to the
GridColumnStylesCollection.

d) Create DataGridColumnStyle instances manually for each of the data
columns. The "DataGridTableStyle Class" topic in the MSDN library gives a
good example on how to do that.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Mike Fellows" <mi*************@equityhouse.co.uk.SPAM> wrote in message
news:sm******************@newsfep2-gui.server.ntli.net...
Below is my code that is carried out on my dataset, datagrid etc...

Im trying to get column0 "Date & Time" to show date and time, not just date
ive read some stuff posted by Dmitriy Lapshin on this board that goes way
over my
ability (this is my first vb or vb.net project). from what I can tell i
need a GridColumnStyles
collection adding to my datagrid but each and everytime I try to do this my code crashes.

It seems such a simple problem that is taking way too long to try and sort, so any help would be greatly appreciated

Regards
Mike Fellows

da.SelectCommand = New OleDbCommand(SQLStr, ocon)
'Fill the DataSet with the Data
da.Fill(ds)

ds.Tables(0).Columns.Item(0).ColumnName = "Date & Time"
ds.Tables(0).Columns.Item(1).ColumnName = "Call Made By"
ds.Tables(0).Columns.Item(2).ColumnName = "Days Since RTB"
ds.Tables(0).Columns.Item(3).ColumnName = "Action"
ds.Tables(0).Columns.Item(4).ColumnName = "Price In"
ds.Tables(0).Columns.Item(5).ColumnName = "Property Valued"
ds.Tables(0).Columns.Item(6).ColumnName = "Notes"

Dim ts As New DataGridTableStyle()
ts.MappingName = "Table"

DataGrid1.TableStyles.Clear()
DataGrid1.TableStyles.Add(ts)
Me.DataGrid1.DataSource = ds.Tables(0)
ts.GridColumnStyles(0).Width = 90
ts.GridColumnStyles(1).Width = 90
ts.GridColumnStyles(2).Width = 100
ts.GridColumnStyles(3).Width = 90
ts.GridColumnStyles(4).Width = 90
ts.GridColumnStyles(5).Width = 90
ts.GridColumnStyles(6).Width = 250
RowCount = ds.Tables(0).Rows.Count
ColumnCount = ds.Tables(0).Columns.Count
da.Dispose()
ds.Dispose()
ocon.Close()
ocon.Dispose()


Nov 20 '05 #3
)
NNTP-Posting-Date: Mon, 20 Oct 2003 13:43:00
Organization: ntl Cablemodem News Service

ok ive tried 2 things

Dim mytime As String
mytime = Me.DataGrid1.Item(0, 0)
MessageBox.Show(mytime)

this showed me that the datagrid was storing the time correclty just not
displaying it

then i tried

Me.DataGrid1.Item(0, 0) = Format(Me.DataGrid1.Item(0, 0), "MM/dd/yyyy
HH:mm:ss")
Dim mytime As String
mytime = Me.DataGrid1.Item(0, 0)
MessageBox.Show(mytime)
im not sure i did the above correctly but it didnt make any difference to
the diaply of the datagrid
and the messagebox still showed the time

so im back to square one :-(


"scorpion53061" <sc************@yahoo.com> wrote in message
news:ux*************@tk2msftngp13.phx.gbl...
First of all never say your code "crashes". It says nothing about the
problem. Always use a Try Catch block to trap the error and report that.

Dates and times throw many beginners for a loop.

i suspect the problem is with your database setup. See the ADO.NET ng about that. If you are using an access database the simple Date/Time field will do what you want. The "General" under format will work nicely.

But lets say you were filling a textbox with a date/time setup and it was
not the way you wanted it:

TextBox7.Text = Format(Date.Now, "MM/dd/yyyy HH:mm:ss")

or

Textbox7.Text = Format(Dsjobitems1.Tables(0).Rows(0).Item("MYDATE" ),
"MM/dd/yyyy")

hope this helps.......


"Mike Fellows" <mi*************@equityhouse.co.uk.SPAM> wrote in message
news:sm******************@newsfep2-gui.server.ntli.net...
Below is my code that is carried out on my dataset, datagrid etc...

Im trying to get column0 "Date & Time" to show date and time, not just

date

ive read some stuff posted by Dmitriy Lapshin on this board that goes way over my
ability (this is my first vb or vb.net project). from what I can tell i
need a GridColumnStyles
collection adding to my datagrid but each and everytime I try to do this

my
code crashes.

It seems such a simple problem that is taking way too long to try and

sort,
so any help would be greatly appreciated

Regards
Mike Fellows

da.SelectCommand = New OleDbCommand(SQLStr, ocon)
'Fill the DataSet with the Data
da.Fill(ds)

ds.Tables(0).Columns.Item(0).ColumnName = "Date & Time"
ds.Tables(0).Columns.Item(1).ColumnName = "Call Made By"
ds.Tables(0).Columns.Item(2).ColumnName = "Days Since RTB"
ds.Tables(0).Columns.Item(3).ColumnName = "Action"
ds.Tables(0).Columns.Item(4).ColumnName = "Price In"
ds.Tables(0).Columns.Item(5).ColumnName = "Property Valued"
ds.Tables(0).Columns.Item(6).ColumnName = "Notes"

Dim ts As New DataGridTableStyle()
ts.MappingName = "Table"

DataGrid1.TableStyles.Clear()
DataGrid1.TableStyles.Add(ts)
Me.DataGrid1.DataSource = ds.Tables(0)
ts.GridColumnStyles(0).Width = 90
ts.GridColumnStyles(1).Width = 90
ts.GridColumnStyles(2).Width = 100
ts.GridColumnStyles(3).Width = 90
ts.GridColumnStyles(4).Width = 90
ts.GridColumnStyles(5).Width = 90
ts.GridColumnStyles(6).Width = 250
RowCount = ds.Tables(0).Rows.Count
ColumnCount = ds.Tables(0).Columns.Count
da.Dispose()
ds.Dispose()
ocon.Close()
ocon.Dispose()


Nov 20 '05 #4
Put a try catch block around the areas that are bombing and tell what it is
reporting....

"Mike Fellows" <mi*************@equityhouse.co.uk.SPAM> wrote in message
news:oL******************@newsfep2-gui.server.ntli.net...
)
NNTP-Posting-Date: Mon, 20 Oct 2003 13:43:00
Organization: ntl Cablemodem News Service

ok ive tried 2 things

Dim mytime As String
mytime = Me.DataGrid1.Item(0, 0)
MessageBox.Show(mytime)

this showed me that the datagrid was storing the time correclty just not
displaying it

then i tried

Me.DataGrid1.Item(0, 0) = Format(Me.DataGrid1.Item(0, 0), "MM/dd/yyyy
HH:mm:ss")
Dim mytime As String
mytime = Me.DataGrid1.Item(0, 0)
MessageBox.Show(mytime)
im not sure i did the above correctly but it didnt make any difference to
the diaply of the datagrid
and the messagebox still showed the time

so im back to square one :-(


"scorpion53061" <sc************@yahoo.com> wrote in message
news:ux*************@tk2msftngp13.phx.gbl...
First of all never say your code "crashes". It says nothing about the
problem. Always use a Try Catch block to trap the error and report that.

Dates and times throw many beginners for a loop.

i suspect the problem is with your database setup. See the ADO.NET ng about
that. If you are using an access database the simple Date/Time field will do
what you want. The "General" under format will work nicely.

But lets say you were filling a textbox with a date/time setup and it was not the way you wanted it:

TextBox7.Text = Format(Date.Now, "MM/dd/yyyy HH:mm:ss")

or

Textbox7.Text = Format(Dsjobitems1.Tables(0).Rows(0).Item("MYDATE" ),
"MM/dd/yyyy")

hope this helps.......


"Mike Fellows" <mi*************@equityhouse.co.uk.SPAM> wrote in message
news:sm******************@newsfep2-gui.server.ntli.net...
Below is my code that is carried out on my dataset, datagrid etc...

Im trying to get column0 "Date & Time" to show date and time, not just

date

ive read some stuff posted by Dmitriy Lapshin on this board that goes way over my
ability (this is my first vb or vb.net project). from what I can tell i need a GridColumnStyles
collection adding to my datagrid but each and everytime I try to do

this my
code crashes.

It seems such a simple problem that is taking way too long to try and

sort,
so any help would be greatly appreciated

Regards
Mike Fellows

da.SelectCommand = New OleDbCommand(SQLStr, ocon)
'Fill the DataSet with the Data
da.Fill(ds)

ds.Tables(0).Columns.Item(0).ColumnName = "Date & Time"
ds.Tables(0).Columns.Item(1).ColumnName = "Call Made By"
ds.Tables(0).Columns.Item(2).ColumnName = "Days Since RTB"
ds.Tables(0).Columns.Item(3).ColumnName = "Action"
ds.Tables(0).Columns.Item(4).ColumnName = "Price In"
ds.Tables(0).Columns.Item(5).ColumnName = "Property Valued"
ds.Tables(0).Columns.Item(6).ColumnName = "Notes"

Dim ts As New DataGridTableStyle()
ts.MappingName = "Table"

DataGrid1.TableStyles.Clear()
DataGrid1.TableStyles.Add(ts)
Me.DataGrid1.DataSource = ds.Tables(0)
ts.GridColumnStyles(0).Width = 90
ts.GridColumnStyles(1).Width = 90
ts.GridColumnStyles(2).Width = 100
ts.GridColumnStyles(3).Width = 90
ts.GridColumnStyles(4).Width = 90
ts.GridColumnStyles(5).Width = 90
ts.GridColumnStyles(6).Width = 250
RowCount = ds.Tables(0).Rows.Count
ColumnCount = ds.Tables(0).Columns.Count
da.Dispose()
ds.Dispose()
ocon.Close()
ocon.Dispose()



Nov 20 '05 #5
sorry you misunderstood

the code that i initially posted has no problems

the problems come when i try to use the gridcolumnstyles which is where i
think
i need to format the data in the datagrid

im sure i need to do somthing like the following:

me.datagrid1.tablestyles(0).gridcolumnstyles("MM/dd/yyyy HH:mm:ss")

but i dont know how to get the datagrid to accept the above (if that makes
sense)
as i recieve the following error "Property access must assign to the
property or use its value."


"scorpion53061" <sc************@yahoo.com> wrote in message
news:#e**************@TK2MSFTNGP09.phx.gbl...
Put a try catch block around the areas that are bombing and tell what it is reporting....

"Mike Fellows" <mi*************@equityhouse.co.uk.SPAM> wrote in message
news:oL******************@newsfep2-gui.server.ntli.net...
)
NNTP-Posting-Date: Mon, 20 Oct 2003 13:43:00
Organization: ntl Cablemodem News Service

ok ive tried 2 things

Dim mytime As String
mytime = Me.DataGrid1.Item(0, 0)
MessageBox.Show(mytime)

this showed me that the datagrid was storing the time correclty just not
displaying it

then i tried

Me.DataGrid1.Item(0, 0) = Format(Me.DataGrid1.Item(0, 0), "MM/dd/yyyy
HH:mm:ss")
Dim mytime As String
mytime = Me.DataGrid1.Item(0, 0)
MessageBox.Show(mytime)
im not sure i did the above correctly but it didnt make any difference to
the diaply of the datagrid
and the messagebox still showed the time

so im back to square one :-(


"scorpion53061" <sc************@yahoo.com> wrote in message
news:ux*************@tk2msftngp13.phx.gbl...
First of all never say your code "crashes". It says nothing about the
problem. Always use a Try Catch block to trap the error and report that.
Dates and times throw many beginners for a loop.

i suspect the problem is with your database setup. See the ADO.NET ng about
that. If you are using an access database the simple Date/Time field will
do
what you want. The "General" under format will work nicely.

But lets say you were filling a textbox with a date/time setup and it

was not the way you wanted it:

TextBox7.Text = Format(Date.Now, "MM/dd/yyyy HH:mm:ss")

or

Textbox7.Text = Format(Dsjobitems1.Tables(0).Rows(0).Item("MYDATE" ),
"MM/dd/yyyy")

hope this helps.......


"Mike Fellows" <mi*************@equityhouse.co.uk.SPAM> wrote in message news:sm******************@newsfep2-gui.server.ntli.net...
> Below is my code that is carried out on my dataset, datagrid etc...
>
> Im trying to get column0 "Date & Time" to show date and time, not just date
>
> ive read some stuff posted by Dmitriy Lapshin on this board that goes way
> over my
> ability (this is my first vb or vb.net project). from what I can
tell i > need a GridColumnStyles
> collection adding to my datagrid but each and everytime I try to do this my
> code crashes.
>
> It seems such a simple problem that is taking way too long to try

and sort,
> so any help would be greatly appreciated
>
> Regards
>
>
> Mike Fellows
>
> da.SelectCommand = New OleDbCommand(SQLStr, ocon)
> 'Fill the DataSet with the Data
> da.Fill(ds)
>
> ds.Tables(0).Columns.Item(0).ColumnName = "Date & Time"
> ds.Tables(0).Columns.Item(1).ColumnName = "Call Made By"
> ds.Tables(0).Columns.Item(2).ColumnName = "Days Since RTB"
> ds.Tables(0).Columns.Item(3).ColumnName = "Action"
> ds.Tables(0).Columns.Item(4).ColumnName = "Price In"
> ds.Tables(0).Columns.Item(5).ColumnName = "Property Valued"
> ds.Tables(0).Columns.Item(6).ColumnName = "Notes"
>
> Dim ts As New DataGridTableStyle()
> ts.MappingName = "Table"
>
> DataGrid1.TableStyles.Clear()
> DataGrid1.TableStyles.Add(ts)
> Me.DataGrid1.DataSource = ds.Tables(0)
> ts.GridColumnStyles(0).Width = 90
> ts.GridColumnStyles(1).Width = 90
> ts.GridColumnStyles(2).Width = 100
> ts.GridColumnStyles(3).Width = 90
> ts.GridColumnStyles(4).Width = 90
> ts.GridColumnStyles(5).Width = 90
> ts.GridColumnStyles(6).Width = 250
> RowCount = ds.Tables(0).Rows.Count
> ColumnCount = ds.Tables(0).Columns.Count
> da.Dispose()
> ds.Dispose()
> ocon.Close()
> ocon.Dispose()
>
>



Nov 20 '05 #6
Mike,
me.datagrid1.tablestyles(0).gridcolumnstyles("MM/dd/yyyy HH:mm:ss")
should be changed to:

me.datagrid1.tablestyles(0).gridcolumnstyles(0).Fo rmat = "MM/dd/yyyy
HH:mm:ss"
^^^
Where the second zero (the one in the parenthes following the
"gridcolumnstyles") should be replaced with the index of the column style
corresponding to the datetime column.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Mike Fellows" <mi*************@equityhouse.co.uk.SPAM> wrote in message
news:Xx******************@newsfep2-gui.server.ntli.net... sorry you misunderstood

the code that i initially posted has no problems

the problems come when i try to use the gridcolumnstyles which is where i
think
i need to format the data in the datagrid

im sure i need to do somthing like the following:

me.datagrid1.tablestyles(0).gridcolumnstyles("MM/dd/yyyy HH:mm:ss")

but i dont know how to get the datagrid to accept the above (if that makes
sense)
as i recieve the following error "Property access must assign to the
property or use its value."


"scorpion53061" <sc************@yahoo.com> wrote in message
news:#e**************@TK2MSFTNGP09.phx.gbl...
Put a try catch block around the areas that are bombing and tell what it

is
reporting....

"Mike Fellows" <mi*************@equityhouse.co.uk.SPAM> wrote in message
news:oL******************@newsfep2-gui.server.ntli.net...
)
NNTP-Posting-Date: Mon, 20 Oct 2003 13:43:00
Organization: ntl Cablemodem News Service

ok ive tried 2 things

Dim mytime As String
mytime = Me.DataGrid1.Item(0, 0)
MessageBox.Show(mytime)

this showed me that the datagrid was storing the time correclty just not displaying it

then i tried

Me.DataGrid1.Item(0, 0) = Format(Me.DataGrid1.Item(0, 0), "MM/dd/yyyy
HH:mm:ss")
Dim mytime As String
mytime = Me.DataGrid1.Item(0, 0)
MessageBox.Show(mytime)
im not sure i did the above correctly but it didnt make any difference to the diaply of the datagrid
and the messagebox still showed the time

so im back to square one :-(


"scorpion53061" <sc************@yahoo.com> wrote in message
news:ux*************@tk2msftngp13.phx.gbl...
> First of all never say your code "crashes". It says nothing about the > problem. Always use a Try Catch block to trap the error and report that. >
> Dates and times throw many beginners for a loop.
>
> i suspect the problem is with your database setup. See the ADO.NET ng about
> that. If you are using an access database the simple Date/Time field

will
do
> what you want. The "General" under format will work nicely.
>
> But lets say you were filling a textbox with a date/time setup and it
was
> not the way you wanted it:
>
> TextBox7.Text = Format(Date.Now, "MM/dd/yyyy HH:mm:ss")
>
> or
>
> Textbox7.Text = Format(Dsjobitems1.Tables(0).Rows(0).Item("MYDATE" ),
> "MM/dd/yyyy")
>
> hope this helps.......
>
>
>
>
> "Mike Fellows" <mi*************@equityhouse.co.uk.SPAM> wrote in message > news:sm******************@newsfep2-gui.server.ntli.net...
> > Below is my code that is carried out on my dataset, datagrid
etc... > >
> > Im trying to get column0 "Date & Time" to show date and time, not just > date
> >
> > ive read some stuff posted by Dmitriy Lapshin on this board that goes way
> > over my
> > ability (this is my first vb or vb.net project). from what I can tell
i
> > need a GridColumnStyles
> > collection adding to my datagrid but each and everytime I try to

do this
> my
> > code crashes.
> >
> > It seems such a simple problem that is taking way too long to try

and > sort,
> > so any help would be greatly appreciated
> >
> > Regards
> >
> >
> > Mike Fellows
> >
> > da.SelectCommand = New OleDbCommand(SQLStr, ocon)
> > 'Fill the DataSet with the Data
> > da.Fill(ds)
> >
> > ds.Tables(0).Columns.Item(0).ColumnName = "Date & Time"
> > ds.Tables(0).Columns.Item(1).ColumnName = "Call Made By"
> > ds.Tables(0).Columns.Item(2).ColumnName = "Days Since RTB"
> > ds.Tables(0).Columns.Item(3).ColumnName = "Action"
> > ds.Tables(0).Columns.Item(4).ColumnName = "Price In"
> > ds.Tables(0).Columns.Item(5).ColumnName = "Property Valued"
> > ds.Tables(0).Columns.Item(6).ColumnName = "Notes"
> >
> > Dim ts As New DataGridTableStyle()
> > ts.MappingName = "Table"
> >
> > DataGrid1.TableStyles.Clear()
> > DataGrid1.TableStyles.Add(ts)
> > Me.DataGrid1.DataSource = ds.Tables(0)
> > ts.GridColumnStyles(0).Width = 90
> > ts.GridColumnStyles(1).Width = 90
> > ts.GridColumnStyles(2).Width = 100
> > ts.GridColumnStyles(3).Width = 90
> > ts.GridColumnStyles(4).Width = 90
> > ts.GridColumnStyles(5).Width = 90
> > ts.GridColumnStyles(6).Width = 250
> > RowCount = ds.Tables(0).Rows.Count
> > ColumnCount = ds.Tables(0).Columns.Count
> > da.Dispose()
> > ds.Dispose()
> > ocon.Close()
> > ocon.Dispose()
> >
> >
>
>




Nov 20 '05 #7
that doesnt work either

that just gives me the compile error:
format' is not a member of 'System.Windows.Forms.DataGridColumnStyle'.

cheers

Mike
"Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.com> wrote
in message news:eL**************@TK2MSFTNGP12.phx.gbl...
Mike,
me.datagrid1.tablestyles(0).gridcolumnstyles("MM/dd/yyyy HH:mm:ss")


should be changed to:

me.datagrid1.tablestyles(0).gridcolumnstyles(0).Fo rmat = "MM/dd/yyyy
HH:mm:ss"
^^^
Where the second zero (the one in the parenthes following the
"gridcolumnstyles") should be replaced with the index of the column style
corresponding to the datetime column.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Mike Fellows" <mi*************@equityhouse.co.uk.SPAM> wrote in message
news:Xx******************@newsfep2-gui.server.ntli.net...
sorry you misunderstood

the code that i initially posted has no problems

the problems come when i try to use the gridcolumnstyles which is where i
think
i need to format the data in the datagrid

im sure i need to do somthing like the following:

me.datagrid1.tablestyles(0).gridcolumnstyles("MM/dd/yyyy HH:mm:ss")

but i dont know how to get the datagrid to accept the above (if that makes sense)
as i recieve the following error "Property access must assign to the
property or use its value."


"scorpion53061" <sc************@yahoo.com> wrote in message
news:#e**************@TK2MSFTNGP09.phx.gbl...
Put a try catch block around the areas that are bombing and tell what it
is
reporting....

"Mike Fellows" <mi*************@equityhouse.co.uk.SPAM> wrote in
message news:oL******************@newsfep2-gui.server.ntli.net...
> )
> NNTP-Posting-Date: Mon, 20 Oct 2003 13:43:00
>
>
> Organization: ntl Cablemodem News Service
>
> ok ive tried 2 things
>
> Dim mytime As String
> mytime = Me.DataGrid1.Item(0, 0)
> MessageBox.Show(mytime)
>
> this showed me that the datagrid was storing the time correclty just

not > displaying it
>
> then i tried
>
> Me.DataGrid1.Item(0, 0) = Format(Me.DataGrid1.Item(0, 0), "MM/dd/yyyy > HH:mm:ss")
> Dim mytime As String
> mytime = Me.DataGrid1.Item(0, 0)
> MessageBox.Show(mytime)
>
>
> im not sure i did the above correctly but it didnt make any difference to
> the diaply of the datagrid
> and the messagebox still showed the time
>
> so im back to square one :-(
>
>
>
>
>
>
> "scorpion53061" <sc************@yahoo.com> wrote in message
> news:ux*************@tk2msftngp13.phx.gbl...
> > First of all never say your code "crashes". It says nothing about the > > problem. Always use a Try Catch block to trap the error and report

that.
> >
> > Dates and times throw many beginners for a loop.
> >
> > i suspect the problem is with your database setup. See the ADO.NET ng > about
> > that. If you are using an access database the simple Date/Time
field will
> do
> > what you want. The "General" under format will work nicely.
> >
> > But lets say you were filling a textbox with a date/time setup and it was
> > not the way you wanted it:
> >
> > TextBox7.Text = Format(Date.Now, "MM/dd/yyyy HH:mm:ss")
> >
> > or
> >
> > Textbox7.Text = Format(Dsjobitems1.Tables(0).Rows(0).Item("MYDATE" ), > > "MM/dd/yyyy")
> >
> > hope this helps.......
> >
> >
> >
> >
> > "Mike Fellows" <mi*************@equityhouse.co.uk.SPAM> wrote in

message
> > news:sm******************@newsfep2-gui.server.ntli.net...
> > > Below is my code that is carried out on my dataset, datagrid etc... > > >
> > > Im trying to get column0 "Date & Time" to show date and time,
not just
> > date
> > >
> > > ive read some stuff posted by Dmitriy Lapshin on this board that

goes
> way
> > > over my
> > > ability (this is my first vb or vb.net project). from what I
can tell
i
> > > need a GridColumnStyles
> > > collection adding to my datagrid but each and everytime I try to do this
> > my
> > > code crashes.
> > >
> > > It seems such a simple problem that is taking way too long to

try and
> > sort,
> > > so any help would be greatly appreciated
> > >
> > > Regards
> > >
> > >
> > > Mike Fellows
> > >
> > > da.SelectCommand = New OleDbCommand(SQLStr, ocon)
> > > 'Fill the DataSet with the Data
> > > da.Fill(ds)
> > >
> > > ds.Tables(0).Columns.Item(0).ColumnName = "Date & Time"
> > > ds.Tables(0).Columns.Item(1).ColumnName = "Call Made By"
> > > ds.Tables(0).Columns.Item(2).ColumnName = "Days Since RTB"
> > > ds.Tables(0).Columns.Item(3).ColumnName = "Action"
> > > ds.Tables(0).Columns.Item(4).ColumnName = "Price In"
> > > ds.Tables(0).Columns.Item(5).ColumnName = "Property Valued"
> > > ds.Tables(0).Columns.Item(6).ColumnName = "Notes"
> > >
> > > Dim ts As New DataGridTableStyle()
> > > ts.MappingName = "Table"
> > >
> > > DataGrid1.TableStyles.Clear()
> > > DataGrid1.TableStyles.Add(ts)
> > > Me.DataGrid1.DataSource = ds.Tables(0)
> > > ts.GridColumnStyles(0).Width = 90
> > > ts.GridColumnStyles(1).Width = 90
> > > ts.GridColumnStyles(2).Width = 100
> > > ts.GridColumnStyles(3).Width = 90
> > > ts.GridColumnStyles(4).Width = 90
> > > ts.GridColumnStyles(5).Width = 90
> > > ts.GridColumnStyles(6).Width = 250
> > > RowCount = ds.Tables(0).Rows.Count
> > > ColumnCount = ds.Tables(0).Columns.Count
> > > da.Dispose()
> > > ds.Dispose()
> > > ocon.Close()
> > > ocon.Dispose()
> > >
> > >
> >
> >
>
>


Nov 20 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by mark | last post: by
1 post views Thread by Simon Harris | last post: by
3 posts views Thread by Mark Wiewel | last post: by
7 posts views Thread by Ausclad | last post: by
2 posts views Thread by rn5a | last post: by
reply views Thread by leo001 | last post: by

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.