getting dates from listview to make dates bold in month calendar

mcfly

Well-known member
Joined
Jun 15, 2009
Messages
54
Programming Experience
Beginner
Hi there,

I have a calendar control that i want the dates to be bolded from values that are taken from a database. The values are pulled from the database into a listview, I was trying to get the values from the listview to be added to an array then this array of dates passed to the calendar control so that the dates from shown in bold? At the moment the code just says is cannot open the database...not sure but i think the logic may be wrong??...anyone any ideas?...

VB.NET:
Dim connetionString As String
        Dim oledbCnn As OleDbConnection
        Dim oledbCmd As OleDbCommand
        Dim sql As String

        connetionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=H:\My Pictures\hotel_db.mdb;User Id=admin;Password=;"
        sql = "Select * from tbl_calendar"

        oledbCnn = New OleDbConnection(connetionString)

        Try
            oledbCnn.Open()
            oledbCmd = New OleDbCommand(sql, oledbCnn)
            Dim oledbReader As OleDbDataReader = oledbCmd.ExecuteReader()
            Do While oledbReader.Read

                Dim arrayList1 As ArrayList = New ArrayList(1)

                ListBox1.Items.Add(oledbReader("date_from")).ToString("yyyy-MM-dd")

                arrayList1.Add(ListBox1.Items)

                Dim i As Integer

                MonthCalendar1.AddBoldedDate(New Date(arrayList1.Item(i + 1)))
                MonthCalendar1.UpdateBoldedDates()
                i = i + 1

                'ListBox1.Items.Add(oledbReader("columnname").ToString())
                'ListBox1.Items.Add(oledbReader(index).ToString())
                'ListBox1.Items.Add(oledbReader(index).ToString())
                'ListBox1.Items.Add(oledbReader("columnname").ToString())

                'ListBox1.Items.Add(oledbReader(0))
                'ListBox1.Items.Add(oledbReader(1))
                'ListBox1.Items.Add(oledbReader(2))

                'TextBox3.Text = oledbReader(0)
                'TextBox4.Text = oledbReader(1)
                'TextBox5.Text = oledbReader(2)
            Loop

            oledbReader.Close()
            oledbCmd.Dispose()
            oledbCnn.Close()
        Catch ex As Exception
            MsgBox("Can not open connection ! ")
        End Try
 
Try this instead of your MsgBox("Something went wrong."):
VB.NET:
MessageBox.Show(ex.Message, ex.GetType.Name)
The whole stacktrace showing line number is available if you do ToString:
VB.NET:
Debug.WriteLine(ex.ToString)
 
i get this error message, which is handy as it gives more information but it doesn't make a lot of sense to me, sorry:

ArgymentOutRangeException : Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

is it something to do with the array i have...

VB.NET:
                arrayList1.Add(ListBox1.Items)

                Dim i As Integer

                MonthCalendar1.AddBoldedDate(New Date(arrayList1.Item(i + 1)))
                MonthCalendar1.UpdateBoldedDates()
                i = i + 1
 
Yes, you have a loop where you each iteration starts the i variable from value 0 and then get the i+1 element. At first iteration you have one item in arraylist and that item has index 0, so i+1=1 is an invalid index. Why do you use ArrayList anyway, I see no use for it in your code, just use a Date variable.
VB.NET:
Dim d As Date = CType(oledbReader("date_from"), Date)
Listbox1.Items.Add(d.ToString("your display format"))
Monthcalendar.AddBoldedDate(d)
Regarding your custom display format, wouldn't it be more wise to use a format that any user of any culture is familiar with? F.ex: d.ToShortDateString()
 
excellent work, this worked a charm :D thank you


VB.NET:
                Dim d As Date = CType(oledbReader("date_from"), Date)
                ListBox1.Items.Add(d.ToShortDateString())
                MonthCalendar1.AddBoldedDate(d)
                MonthCalendar1.UpdateBoldedDates()
 
Back
Top