VB.NET School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 300,416 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,574 people online right now. Registration is fast and FREE... Join Now!




MonthCalendar need dates to be highlighted or bolded

 

MonthCalendar need dates to be highlighted or bolded

jimdandy75

29 Jun, 2009 - 05:26 PM
Post #1

D.I.C Head
**

Joined: 30 Jun, 2008
Posts: 73



Thanked: 2 times
My Contributions
Ok, I made a small program that's a calendar that allows you to add notes to selected days. Then when you click on the days again it retrieves and displays the notes or allows you to edit and so forth. It works through an MS Access db. I want the days that have notes to be highlighted or bold. I know this bit of code works, for bold :

CODE
Me.MonthCalendar1.BoldedDates = New System.DateTime() {New System.DateTime(2009, 6, 24, 0, 0, 0, 0)}


but I have no idea how I could add this to the Form1_Load sub from the Add Note button. So when the program is opened, the dates with notes are highlighted (bolded). The date format is completely different. Any help or fresh ideas would be greatly appreciated. Here's the code I have so far. Thanks biggrin.gif

CODE

Imports System.IO
Imports System.Data
Imports System.Data.OleDb
Public Class Form1
    Private strSQL As String = ""
    Private command As OleDbCommand
    Private connection As OleDbConnection = New OleDbConnection(My.Settings.notesConnectionString)

    Dim cn As OleDbConnection
    Dim cmd As OleDbCommand
    Dim dr As OleDbDataReader

    Private Sub MonthCalendar1_DateChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DateRangeEventArgs) Handles MonthCalendar1.DateChanged
        txtDates.Text = MonthCalendar1.SelectionStart.ToShortDateString
        btnAddNote.Hide()
        txtNotes.Select()
        txtNotes.SelectionStart = txtNotes.TextLength
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        'Me.MonthCalendar1.BoldedDates = New System.DateTime() {New System.DateTime(2009, 6, 24, 0, 0, 0, 0)}

    End Sub

    Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtNotes.TextChanged
        btnAddNote.Show()
    End Sub

    Private Sub btnAddNote_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddNote.Click
        Try

            Dim day As String
            day = txtDates.Text

            Dim note As String
            note = txtNotes.Text

            connection.Open()
            If txtNotes.Text = "" Then
                MessageBox.Show("Type a note, then press Enter...", "Warning !!!!!", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                txtNotes.Select()
            Else
                strSQL = "DELETE FROM calendar WHERE day = '" & day & "'"
                command = New OleDbCommand(strSQL, connection)
                command.ExecuteNonQuery()

                strSQL = "Insert into calendar([day], [note]) Values('" & day & "', '" & note & "')"
                command = New OleDbCommand(strSQL, connection)
                command.ExecuteNonQuery()
                connection.Close()
            End If
        Catch ex As Exception
            MessageBox.Show("An error occurred, please restart Calendar and try again...", "Warning !!!!!", MessageBoxButtons.OK, MessageBoxIcon.Warning)
        End Try

        btnAddNote.Hide()
        connection.Close()
    End Sub

    Private Sub txtDates_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtDates.TextChanged

        cn = New OleDbConnection(My.Settings.notesConnectionString)
        'provider to be used when working with access database
        cn.Open()

        Try
            txtNotes.Clear()
            cmd = New OleDbCommand("Select note FROM calendar where day = '" & txtDates.Text & "'", cn)
            dr = cmd.ExecuteReader
            While dr.Read()
                txtNotes.Text = CStr(dr(0))
            End While

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
End Class


Attached Image

This post has been edited by jimdandy75: 29 Jun, 2009 - 05:28 PM

User is offlineProfile CardPM
+Quote Post


erickh

RE: MonthCalendar Need Dates To Be Highlighted Or Bolded

29 Jun, 2009 - 06:15 PM
Post #2

New D.I.C Head
*

Joined: 24 Jun, 2009
Posts: 10


My Contributions

There's a property in the monthly calendar control that contains an array of bolded dates. You can set or get this property.

CODE

Dim MyDateArray() As Date
' put dates in your date array
MyCalendar.MonthlyBoldedDates = MyDateArray


So on form_load you would SELECT the dates from your db table and them in your array, and then assign your calendar control MonthlyBoldedDates property to the array.

Cheers!
Erick



User is offlineProfile CardPM
+Quote Post

jimdandy75

RE: MonthCalendar Need Dates To Be Highlighted Or Bolded

30 Jun, 2009 - 07:08 AM
Post #3

D.I.C Head
**

Joined: 30 Jun, 2008
Posts: 73



Thanked: 2 times
My Contributions
Thanks for the help, but it's not working, the dates load into the db in short version (6/30/2009). This doesn't work in the array anyway I try it. When I set the Bolded property on the property menu, this is how it writes the code in the Form1.Designer.vb
CODE
Me.MonthCalendar1.BoldedDates = New Date() {New Date(2009, 6, 30, 0, 0, 0, 0)}

this would be how the code would have to look in the load form also, or I don't think it will work??? blink.gif
User is offlineProfile CardPM
+Quote Post

jimdandy75

RE: MonthCalendar Need Dates To Be Highlighted Or Bolded

30 Jun, 2009 - 02:04 PM
Post #4

D.I.C Head
**

Joined: 30 Jun, 2008
Posts: 73



Thanked: 2 times
My Contributions
Well, I came up with a work around. It splits the short date into an array. Then I use that to build a string like so:

CODE

   Dim str As String
        str = txtDates.Text

        Dim strArray() As String = str.Split("/")

        Dim boldDate As String = "Me.MonthCalendar1.BoldedDates = New Date() {New Date(" + strArray(2) _
        + ", " + strArray(0) + ", " + strArray(1) + ", 0, 0, 0, 0)}"
        txtBoldDateString.Text = boldDate


now my problem is; how do I place the string from txtBoldDateString, into Form1_Load Sub, with the add note button?
Tried this, doesn't work..... blink.gif
CODE
Dim x As String = txtBoldDateString.Text
            add(x).Form1_Load()


Thank you !!!!
User is offlineProfile CardPM
+Quote Post

jimdandy75

RE: MonthCalendar Need Dates To Be Highlighted Or Bolded

30 Jun, 2009 - 03:20 PM
Post #5

D.I.C Head
**

Joined: 30 Jun, 2008
Posts: 73



Thanked: 2 times
My Contributions
How bout this, is it even possible to add additional code to your program, through a button event like I want to do here?
If I could add the bit of code to Form1_Load whenever a note is added, then that day will be highlighted every time I restart the program and I'll know which days have notes. ....................... blink.gif
User is offlineProfile CardPM
+Quote Post

jimdandy75

RE: MonthCalendar Need Dates To Be Highlighted Or Bolded

1 Jul, 2009 - 05:44 AM
Post #6

D.I.C Head
**

Joined: 30 Jun, 2008
Posts: 73



Thanked: 2 times
My Contributions
Anyone?????????????
User is offlineProfile CardPM
+Quote Post

jimdandy75

RE: MonthCalendar Need Dates To Be Highlighted Or Bolded

3 Jul, 2009 - 09:23 AM
Post #7

D.I.C Head
**

Joined: 30 Jun, 2008
Posts: 73



Thanked: 2 times
My Contributions
crazy.gif MAN!!! I'm still stumped on this. I've been trying it like Erickh said with the array, but I suck at arrays. Could someone please help me with this? 'day' is the column where the short dates are stored and calendar is the table. I know my problem has to do with the array though.
CODE
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        cn = New OleDbConnection(My.Settings.notesConnectionString)
        'provider to be used when working with access database
        cn.Open()

        Dim MyDateArray() As Date

        Try
            cmd = New OleDbCommand("Select day FROM calendar", cn)
            dr = cmd.ExecuteReader
            While dr.Read()
                MyDateArray = (dr(0))
            End While

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

        ' put days in the date array ????!!!!!
        MonthCalendar1.MonthlyBoldedDates = MyDateArray
    End Sub

User is offlineProfile CardPM
+Quote Post

sonia.sardana

RE: MonthCalendar Need Dates To Be Highlighted Or Bolded

3 Jul, 2009 - 09:49 AM
Post #8

D.I.C Head
**

Joined: 1 Jun, 2008
Posts: 132



Thanked: 5 times
My Contributions
Is the problem solved or still pending,U want to highlight bold dates on form_Load....If probs not solved,Tell me up,I know the solution???
User is offlineProfile CardPM
+Quote Post

jimdandy75

RE: MonthCalendar Need Dates To Be Highlighted Or Bolded

3 Jul, 2009 - 10:16 AM
Post #9

D.I.C Head
**

Joined: 30 Jun, 2008
Posts: 73



Thanked: 2 times
My Contributions
no I haven't solved it. I know how to do it on the property menu, but I want it to get the dates that have notes from my db and on form load highlight them. I'd really appreciate your help, thanks biggrin.gif
User is offlineProfile CardPM
+Quote Post

ritu verma

RE: MonthCalendar Need Dates To Be Highlighted Or Bolded

3 Jul, 2009 - 10:39 AM
Post #10

New D.I.C Head
*

Joined: 10 Apr, 2009
Posts: 16

fffffffffffffff

This post has been edited by ritu verma: 3 Jul, 2009 - 10:39 AM
User is offlineProfile CardPM
+Quote Post

sonia.sardana

RE: MonthCalendar Need Dates To Be Highlighted Or Bolded

3 Jul, 2009 - 10:40 AM
Post #11

D.I.C Head
**

Joined: 1 Jun, 2008
Posts: 132



Thanked: 5 times
My Contributions
CODE

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Call ADDBOLD(2009, 7, 5)
        Call ADDBOLD(2009, 7, 6)
    End Sub

    Private Sub ADDBOLD(ByVal Year As Integer, ByVal month As Integer, ByVal day As Integer)
        MonthCalendarr.AddBoldedDate(New Date(Year, month, day))
        MonthCalendarr.UpdateBoldedDates()
    End Sub


Is this u r looking for??? If need any help,den reply.
User is offlineProfile CardPM
+Quote Post

jimdandy75

RE: MonthCalendar Need Dates To Be Highlighted Or Bolded

3 Jul, 2009 - 10:46 AM
Post #12

D.I.C Head
**

Joined: 30 Jun, 2008
Posts: 73



Thanked: 2 times
My Contributions
QUOTE
Is this u r looking for??? If need any help,den reply.


I don't know this doesn't look like it'll get the dates out of my db that have notes?

User is offlineProfile CardPM
+Quote Post

sonia.sardana

RE: MonthCalendar Need Dates To Be Highlighted Or Bolded

5 Jul, 2009 - 08:11 AM
Post #13

D.I.C Head
**

Joined: 1 Jun, 2008
Posts: 132



Thanked: 5 times
My Contributions
ya u just have to change the dates..Nothing else dear...Or post ur full code here including ur Db,i will solve it..
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/7/09 11:30PM

Live VB.NET Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month