Results 1 to 5 of 5

Thread: getting dates from listview to make dates bold in month calendar

  1. #1
    mcfly is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Jun 2009
    Posts
    54
    Reputation
    67

    getting dates from listview to make dates bold in month calendar

    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?...

    Code:
    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

  2. #2
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    14,506
    Reputation
    2734
    Try this instead of your MsgBox("Something went wrong."):
    Code:
    MessageBox.Show(ex.Message, ex.GetType.Name)
    The whole stacktrace showing line number is available if you do ToString:
    Code:
    Debug.WriteLine(ex.ToString)

  3. #3
    mcfly is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Jun 2009
    Posts
    54
    Reputation
    67
    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...

    Code:
                    arrayList1.Add(ListBox1.Items)
    
                    Dim i As Integer
    
                    MonthCalendar1.AddBoldedDate(New Date(arrayList1.Item(i + 1)))
                    MonthCalendar1.UpdateBoldedDates()
                    i = i + 1

  4. #4
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    14,506
    Reputation
    2734
    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.
    Code:
    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()

  5. #5
    mcfly is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Jun 2009
    Posts
    54
    Reputation
    67
    excellent work, this worked a charm thank you


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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Harvest time tracking