12 Replies - 10697 Views - Last Post: 05 July 2009 - 09:11 AM Rate Topic: -----

#1 jimdandy75  Icon User is offline

  • D.I.C Regular

Reputation: 37
  • View blog
  • Posts: 311
  • Joined: 30-June 08

MonthCalendar need dates to be highlighted or bolded

Posted 29 June 2009 - 06:26 PM

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 :

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

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 June 2009 - 06:28 PM


Is This A Good Question/Topic? 0
  • +

Replies To: MonthCalendar need dates to be highlighted or bolded

#2 erickh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 24-June 09

Re: MonthCalendar need dates to be highlighted or bolded

Posted 29 June 2009 - 07:15 PM

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

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
Was This Post Helpful? 0
  • +
  • -

#3 jimdandy75  Icon User is offline

  • D.I.C Regular

Reputation: 37
  • View blog
  • Posts: 311
  • Joined: 30-June 08

Re: MonthCalendar need dates to be highlighted or bolded

Posted 30 June 2009 - 08:08 AM

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
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:
Was This Post Helpful? 0
  • +
  • -

#4 jimdandy75  Icon User is offline

  • D.I.C Regular

Reputation: 37
  • View blog
  • Posts: 311
  • Joined: 30-June 08

Re: MonthCalendar need dates to be highlighted or bolded

Posted 30 June 2009 - 03:04 PM

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:

   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:
 Dim x As String = txtBoldDateString.Text
			add(x).Form1_Load()


Thank you !!!!
Was This Post Helpful? 0
  • +
  • -

#5 jimdandy75  Icon User is offline

  • D.I.C Regular

Reputation: 37
  • View blog
  • Posts: 311
  • Joined: 30-June 08

Re: MonthCalendar need dates to be highlighted or bolded

Posted 30 June 2009 - 04:20 PM

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:
Was This Post Helpful? 0
  • +
  • -

#6 jimdandy75  Icon User is offline

  • D.I.C Regular

Reputation: 37
  • View blog
  • Posts: 311
  • Joined: 30-June 08

Re: MonthCalendar need dates to be highlighted or bolded

Posted 01 July 2009 - 06:44 AM

Anyone?????????????
Was This Post Helpful? 0
  • +
  • -

#7 jimdandy75  Icon User is offline

  • D.I.C Regular

Reputation: 37
  • View blog
  • Posts: 311
  • Joined: 30-June 08

Re: MonthCalendar need dates to be highlighted or bolded

Posted 03 July 2009 - 10:23 AM

:crazy: 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.
 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

Was This Post Helpful? 0
  • +
  • -

#8 sonia.sardana  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 132
  • Joined: 01-June 08

Re: MonthCalendar need dates to be highlighted or bolded

Posted 03 July 2009 - 10:49 AM

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???
Was This Post Helpful? 0
  • +
  • -

#9 jimdandy75  Icon User is offline

  • D.I.C Regular

Reputation: 37
  • View blog
  • Posts: 311
  • Joined: 30-June 08

Re: MonthCalendar need dates to be highlighted or bolded

Posted 03 July 2009 - 11:16 AM

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 :D
Was This Post Helpful? 0
  • +
  • -

#10 ritu verma  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 10-April 09

Re: MonthCalendar need dates to be highlighted or bolded

Posted 03 July 2009 - 11:39 AM

fffffffffffffff

This post has been edited by ritu verma: 03 July 2009 - 11:39 AM

Was This Post Helpful? 0
  • +
  • -

#11 sonia.sardana  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 132
  • Joined: 01-June 08

Re: MonthCalendar need dates to be highlighted or bolded

Posted 03 July 2009 - 11:40 AM

 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.
Was This Post Helpful? 0
  • +
  • -

#12 jimdandy75  Icon User is offline

  • D.I.C Regular

Reputation: 37
  • View blog
  • Posts: 311
  • Joined: 30-June 08

Re: MonthCalendar need dates to be highlighted or bolded

Posted 03 July 2009 - 11:46 AM

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?
Was This Post Helpful? 0
  • +
  • -

#13 sonia.sardana  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 132
  • Joined: 01-June 08

Re: MonthCalendar need dates to be highlighted or bolded

Posted 05 July 2009 - 09:11 AM

ya u just have to change the dates..Nothing else dear...Or post ur full code here including ur Db,i will solve it..
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1