Best Method

  • Thread starter Thread starter Brian
  • Start date Start date
B

Brian

I am looking for a way to store maybe in an array or dictionary... two
fields....
first field would be a string... second would be a date...
for example.. if i called up myinfo(0) it would show "the first Day"
"1/1/2008" ???
Brian
 
I am looking for a way to store maybe in an array or dictionary... two
fields....
first field would be a string... second would be a date...
for example.. if i called up myinfo(0) it would show "the first Day"
"1/1/2008" ???
Brian

Sounds to me you just need to make a custom class that has two
properties, label and date:

//////////////
Public Class YourClassNameHere

Private _Label As String = String.Empty
Private _TheDate As DateTime = DateTime.Now

Public Sub New()

End Sub

Public Sub New(ByVal label As String, ByVal theDate As DateTime)
Me.New()

Me.Label = label
Me.TheDate = TheDate
End Sub

Public Property Label As String
Get
Return _Label
End Get
Set (ByVal value As String)
_Label = value
End Set
End Property

Public Property TheDate As DateTime
Get
Return _TheDate
End Get
Set (ByVal value As DateTime)
_TheDate = value
End Set
End Property

'// I typed this in the message so this statement might
'// not be formatted correctly
Public Overrides Function ToString() As String
Return String.Format("{0} {1}", Me.Label, Me.TheDate)
End Function

End Class
//////////////

Then you could just store these objects in any sort of IEnumerable
field (array, list, arraylist, etc) and then when you pull them out of
the array (or whatever) and call the .ToString() method, you will get
the string like you requested.

Thanks,

Seth Rowe [MVP]
 
Simple and best approach for implementing this in .Net Framework 2.0 is to
create collection of Type Generic and define the Type of the value that you
will persist. This will solve majority of the problems. Also this is good in
terms of performance.

Thanks,
Mayur H Chauhan
 
Hi Seth,

Is this not more simple as it has to be in an array.

Dim myArray() as String = {"The first Day", "1/1/2008"}

I could not make more from the question of the OP.

:-)

Cor
 
Hi Seth,

Is this not more simple as it has to be in an array.

Dim myArray() as String = {"The first Day", "1/1/2008"}

I could not make more from the question of the OP.

:-)

Cor

The twist I saw was that he wanted to display both the label and the
date together, hence my ToString() override. Though you are correct,
the question was a bit vague to give an accurate answer.

Thanks,

Seth Rowe [MVP]
 
ok,, let me try to tell say it different way what I am wanting to do.
I want to have a collection of dates to add to the monthcalendar.boldeddates
but, I would like to list the dates I have bolded in something like a text
box.... and show that
1/1/2008 is New Years day... "New Years Day 1/1/2008"
and I'll have a list of holidays for collection...
 
The shortest way I now with one row

\\\\
dim dt as new datatable
dim dcfirstcolumn as new datacolumn("first")
dim dcsecondcolumn as new datacolumn("second")
dt.colums.add(dcfirstcolumn)
dt.colums.add(dcsecondcolumn)
dim dr as new datarow = dt.rows.newrow
dr(dcfirstcolumn) = "The first Day"
dr(dcsecondcolumn) = "1/2/2008"
dt.rows.add(dr)
myListBox.DataSource = dt
myListBox.DisplayMember = "first"
myListbox.ValueMember = "second"
///

Typed in this message so watch errors.

Cor
 
Back
Top