|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
use variable as textbox name?I use following code to update a textbox when a date has been chosen from my MonthCalendar. Since 6 textboxes use the same MonthCalendar I need to tell him which textbox was used. Therefore I have the variable: sWhichDateBox. How can I use that string to become the name of a textbox: SelectedTextBox.Text = m_picker.SelectionRange.Start.Date.ToShortDateString() Private Sub m_picker_DateChanged(ByVal sender As Object, _ ByVal e As DateRangeEventArgs) Handles m_picker.DateChanged Dim hti As MonthCalendar.HitTestInfo = m_picker.HitTest (m_picker.PointToClient(MousePosition)) Dim SelectedTextBox As TextBox = Nothing SelectedTextBox.Name = sWhichDateBox 'Display the Start and End property values of 'the SelectionRange object in the text boxes. SelectedTextBox.Text = m_picker.SelectionRange.Start.Date.ToShortDateString() SelectedTextBox.Text = m_picker.SelectionRange.End.Date.ToShortDateString() 'if we clicked on a date then hide the Calendar If hti.HitArea = MonthCalendar.HitArea.Date Then m_picker.Hide() SelectedTextBox.Parent.Controls.Remove(m_picker) m_picker = Nothing bCalOpened = False End If End Sub Regards Marco The Netherlands Try using the user-defined Tag property for each text box.
-- Show quoteHide quoteCo wrote: > Hi All, > > I use following code to update a textbox when a date has been chosen > from my MonthCalendar. > Since 6 textboxes use the same MonthCalendar I need to tell him which > textbox was used. > Therefore I have the variable: sWhichDateBox. > How can I use that string to become the name of a textbox: > SelectedTextBox.Text = > m_picker.SelectionRange.Start.Date.ToShortDateString() > > > Private Sub m_picker_DateChanged(ByVal sender As Object, _ > ByVal e As DateRangeEventArgs) Handles m_picker.DateChanged > > Dim hti As MonthCalendar.HitTestInfo = m_picker.HitTest > (m_picker.PointToClient(MousePosition)) > Dim SelectedTextBox As TextBox = Nothing > SelectedTextBox.Name = sWhichDateBox > 'Display the Start and End property values of > 'the SelectionRange object in the text boxes. > SelectedTextBox.Text = > m_picker.SelectionRange.Start.Date.ToShortDateString() > SelectedTextBox.Text = > m_picker.SelectionRange.End.Date.ToShortDateString() > > 'if we clicked on a date then hide the Calendar > If hti.HitArea = MonthCalendar.HitArea.Date Then > m_picker.Hide() > SelectedTextBox.Parent.Controls.Remove(m_picker) > m_picker = Nothing > bCalOpened = False > End If > End Sub > > Regards > Marco > The Netherlands On 23 mei, 19:06, Mike <unkn***@unknown.tv> wrote:
Show quoteHide quote > Try using the user-defined Tag property for each text box. I've been trying this:> > -- > > Co wrote: > > Hi All, > > > I use following code to update a textbox when a date has been chosen > > from my MonthCalendar. > > Since 6 textboxes use the same MonthCalendar I need to tell him which > > textbox was used. > > Therefore I have the variable: sWhichDateBox. > > How can I use that string to become the name of a textbox: > > SelectedTextBox.Text = > > m_picker.SelectionRange.Start.Date.ToShortDateString() > > > Private Sub m_picker_DateChanged(ByVal sender As Object, _ > > ByVal e As DateRangeEventArgs) Handles m_picker.DateChanged > > > Dim hti As MonthCalendar.HitTestInfo = m_picker.HitTest > > (m_picker.PointToClient(MousePosition)) > > Dim SelectedTextBox As TextBox = Nothing > > SelectedTextBox.Name = sWhichDateBox > > 'Display the Start and End property values of > > 'the SelectionRange object in the text boxes. > > SelectedTextBox.Text = > > m_picker.SelectionRange.Start.Date.ToShortDateString() > > SelectedTextBox.Text = > > m_picker.SelectionRange.End.Date.ToShortDateString() > > > 'if we clicked on a date then hide the Calendar > > If hti.HitArea = MonthCalendar.HitArea.Date Then > > m_picker.Hide() > > SelectedTextBox.Parent.Controls.Remove(m_picker) > > m_picker = Nothing > > bCalOpened = False > > End If > > End Sub > > > Regards > > Marco > > The Netherlands Dim textBoxNew As New TextBox textBoxNew.Name = "tbVerlooptTot" m_Controls.Add(textBoxNew.Name, textBoxNew) Dim textBoxNew2 As New TextBox textBoxNew2.Name = "tbVerlooptVan" m_Controls.Add(textBoxNew2.Name, textBoxNew2) Dim textBoxNew3 As New TextBox textBoxNew3.Name = "tbGemaaktTot" m_Controls.Add(textBoxNew3.Name, textBoxNew3) Private Sub CreateDTP() Dim t As TextBox = DirectCast(m_Controls.Item(iDateBox), TextBox) bCalOpened = True m_picker = New MonthCalendar m_picker.BringToFront() m_picker.MaxSelectionCount = 1 m_picker.Size = t.Size m_picker.BackColor = Color.Beige Me.Parent.Controls(0).Controls.Clear() Me.Parent.Controls(0).Controls.Add(m_picker) m_picker.BringToFront() m_picker.Select() End Sub Private Sub m_picker_DateChanged(ByVal sender As Object, _ ByVal e As DateRangeEventArgs) Handles m_picker.DateChanged Dim hti As MonthCalendar.HitTestInfo = m_picker.HitTest (m_picker.PointToClient(MousePosition)) Dim t As TextBox = DirectCast(m_Controls.Item(iDateBox), TextBox) 'Display the Start and End property values of 'the SelectionRange object in the text boxes. t.Text = m_picker.SelectionRange.Start.Date.ToShortDateString () t.Text = m_picker.SelectionRange.End.Date.ToShortDateString() 'if we clicked on a date then hide the Calendar If hti.HitArea = MonthCalendar.HitArea.Date Then m_picker.Hide() Me.Parent.Controls(0).Controls.Remove(m_picker) m_picker = Nothing bCalOpened = False End If End Sub But I keep getting an error saying I should use the New instance. "Object reference not set to an instance of an object" Marco Maybe that isn't useful for you, but I thought I mention it. :-)
I was referring to the Tag property that is a persistent user-defined element. Dim tb As TextBox tb = New TextBox : tb.Tag = "Tot" : m_Controls.Add(tb.Tag, tb) tb = New TextBox : tb.Tag = "Van" : m_Controls.Add(tb.Tag, tb) tb = New TextBox : tb.Tag = "Gemaakt" : m_Controls.Add(tb.Tag, tb) This is very useful for when the user-defined element is more complex, like a key or reference or pointer to some data associations to link to some other controls. -- Show quoteHide quoteCo wrote: > On 23 mei, 19:06, Mike <unkn***@unknown.tv> wrote: >> Try using the user-defined Tag property for each text box. >> >> -- >> > I've been trying this: > > Dim textBoxNew As New TextBox > textBoxNew.Name = "tbVerlooptTot" > m_Controls.Add(textBoxNew.Name, textBoxNew) > Dim textBoxNew2 As New TextBox > textBoxNew2.Name = "tbVerlooptVan" > m_Controls.Add(textBoxNew2.Name, textBoxNew2) > Dim textBoxNew3 As New TextBox > textBoxNew3.Name = "tbGemaaktTot" > m_Controls.Add(textBoxNew3.Name, textBoxNew3) > > Private Sub CreateDTP() > > Dim t As TextBox = DirectCast(m_Controls.Item(iDateBox), > TextBox) > bCalOpened = True > m_picker = New MonthCalendar > m_picker.BringToFront() > m_picker.MaxSelectionCount = 1 > m_picker.Size = t.Size > m_picker.BackColor = Color.Beige > Me.Parent.Controls(0).Controls.Clear() > Me.Parent.Controls(0).Controls.Add(m_picker) > m_picker.BringToFront() > m_picker.Select() > > End Sub > > Private Sub m_picker_DateChanged(ByVal sender As Object, _ > ByVal e As DateRangeEventArgs) Handles m_picker.DateChanged > > Dim hti As MonthCalendar.HitTestInfo = m_picker.HitTest > (m_picker.PointToClient(MousePosition)) > Dim t As TextBox = DirectCast(m_Controls.Item(iDateBox), > TextBox) > > > 'Display the Start and End property values of > 'the SelectionRange object in the text boxes. > t.Text = m_picker.SelectionRange.Start.Date.ToShortDateString > () > t.Text = m_picker.SelectionRange.End.Date.ToShortDateString() > > 'if we clicked on a date then hide the Calendar > If hti.HitArea = MonthCalendar.HitArea.Date Then > m_picker.Hide() > Me.Parent.Controls(0).Controls.Remove(m_picker) > m_picker = Nothing > bCalOpened = False > End If > End Sub > > But I keep getting an error saying I should use the New instance. > "Object reference not set to an instance of an object" > > Marco On Sat, 23 May 2009 10:20:09 -0700 (PDT), Co <vonclausow***@gmail.com>
wrote: Show quoteHide quote >On 23 mei, 19:06, Mike <unkn***@unknown.tv> wrote: First, when you say you get an error, TELL US WHICH LINE GETS THE>> Try using the user-defined Tag property for each text box. >> >> -- >> >> Co wrote: >> > Hi All, >> >> > I use following code to update a textbox when a date has been chosen >> > from my MonthCalendar. >> > Since 6 textboxes use the same MonthCalendar I need to tell him which >> > textbox was used. >> > Therefore I have the variable: sWhichDateBox. >> > How can I use that string to become the name of a textbox: >> > SelectedTextBox.Text = >> > m_picker.SelectionRange.Start.Date.ToShortDateString() >> >> > Private Sub m_picker_DateChanged(ByVal sender As Object, _ >> > ByVal e As DateRangeEventArgs) Handles m_picker.DateChanged >> >> > Dim hti As MonthCalendar.HitTestInfo = m_picker.HitTest >> > (m_picker.PointToClient(MousePosition)) >> > Dim SelectedTextBox As TextBox = Nothing >> > SelectedTextBox.Name = sWhichDateBox >> > 'Display the Start and End property values of >> > 'the SelectionRange object in the text boxes. >> > SelectedTextBox.Text = >> > m_picker.SelectionRange.Start.Date.ToShortDateString() >> > SelectedTextBox.Text = >> > m_picker.SelectionRange.End.Date.ToShortDateString() >> >> > 'if we clicked on a date then hide the Calendar >> > If hti.HitArea = MonthCalendar.HitArea.Date Then >> > m_picker.Hide() >> > SelectedTextBox.Parent.Controls.Remove(m_picker) >> > m_picker = Nothing >> > bCalOpened = False >> > End If >> > End Sub >> >> > Regards >> > Marco >> > The Netherlands > >I've been trying this: > > Dim textBoxNew As New TextBox > textBoxNew.Name = "tbVerlooptTot" > m_Controls.Add(textBoxNew.Name, textBoxNew) > Dim textBoxNew2 As New TextBox > textBoxNew2.Name = "tbVerlooptVan" > m_Controls.Add(textBoxNew2.Name, textBoxNew2) > Dim textBoxNew3 As New TextBox > textBoxNew3.Name = "tbGemaaktTot" > m_Controls.Add(textBoxNew3.Name, textBoxNew3) > >Private Sub CreateDTP() > > Dim t As TextBox = DirectCast(m_Controls.Item(iDateBox), >TextBox) > bCalOpened = True > m_picker = New MonthCalendar > m_picker.BringToFront() > m_picker.MaxSelectionCount = 1 > m_picker.Size = t.Size > m_picker.BackColor = Color.Beige > Me.Parent.Controls(0).Controls.Clear() > Me.Parent.Controls(0).Controls.Add(m_picker) > m_picker.BringToFront() > m_picker.Select() > > End Sub > > Private Sub m_picker_DateChanged(ByVal sender As Object, _ > ByVal e As DateRangeEventArgs) Handles m_picker.DateChanged > > Dim hti As MonthCalendar.HitTestInfo = m_picker.HitTest >(m_picker.PointToClient(MousePosition)) > Dim t As TextBox = DirectCast(m_Controls.Item(iDateBox), >TextBox) > > > 'Display the Start and End property values of > 'the SelectionRange object in the text boxes. > t.Text = m_picker.SelectionRange.Start.Date.ToShortDateString >() > t.Text = m_picker.SelectionRange.End.Date.ToShortDateString() > > 'if we clicked on a date then hide the Calendar > If hti.HitArea = MonthCalendar.HitArea.Date Then > m_picker.Hide() > Me.Parent.Controls(0).Controls.Remove(m_picker) > m_picker = Nothing > bCalOpened = False > End If > End Sub > >But I keep getting an error saying I should use the New instance. >"Object reference not set to an instance of an object" > >Marco ERROR. Most people will read this post and ignore it, because it is too much work to look through your lengthy code to try to figure out which line might get that error. My guess is that the error occurs on the second of these lines: Dim textBoxNew As New TextBox textBoxNew.Name = "tbVerlooptTot" "Dim textBoxNew As New TextBox" does not create at TextBox object. It creates a variable named textBoxNew that contains Nothing. You need to create a TextBox object. You need to do this: Dim textBoxNew As TextBox = New TextBox textBoxNew.Name = "tbVerlooptTot" Jack Jackson wrote:
> My guess is that the error occurs on the second of these lines: Oh yes it does: "Dim textBoxNew As New TextBox" is short for "Dim textBoxNew > > Dim textBoxNew As New TextBox > textBoxNew.Name = "tbVerlooptTot" > > "Dim textBoxNew As New TextBox" does not create at TextBox object. As TextBox = New TextBox". Andrew On Tue, 26 May 2009 15:38:05 +0100, "Andrew Morton"
<a**@in-press.co.uk.invalid> wrote: >Jack Jackson wrote: My mistake. I meant to say "Dim textBoxNew As TextBox".>> My guess is that the error occurs on the second of these lines: >> >> Dim textBoxNew As New TextBox >> textBoxNew.Name = "tbVerlooptTot" >> >> "Dim textBoxNew As New TextBox" does not create at TextBox object. > >Oh yes it does: "Dim textBoxNew As New TextBox" is short for "Dim textBoxNew >As TextBox = New TextBox". > >Andrew > Co wrote:
> Hi All, Is there a reason why you don't declare "WhichDateBox As Textbox"?> > I use following code to update a textbox when a date has been chosen > from my MonthCalendar. > Since 6 textboxes use the same MonthCalendar I need to tell him which > textbox was used. > Therefore I have the variable: sWhichDateBox. Armin On 23 mei, 19:12, "Armin Zingler" <az.nos***@freenet.de> wrote: That didn't work either.> Co wrote: > > Hi All, > > > I use following code to update a textbox when a date has been chosen > > from my MonthCalendar. > > Since 6 textboxes use the same MonthCalendar I need to tell him which > > textbox was used. > > Therefore I have the variable: sWhichDateBox. > > Is there a reason why you don't declare "WhichDateBox As Textbox"? > > Armin Co wrote:
>> What does not work? What did you try? More information, please.>>> I use following code to update a textbox when a date has been chosen >>> from my MonthCalendar. >>> Since 6 textboxes use the same MonthCalendar I need to tell him >>> which textbox was used. >>> Therefore I have the variable: sWhichDateBox. >> >> Is there a reason why you don't declare "WhichDateBox As Textbox"? >> >> Armin > > That didn't work either. Armin
Show quote
Hide quote
On 23 mei, 20:32, "Armin Zingler" <az.nos***@freenet.de> wrote: I can only create a New textbox.> Co wrote: > > >>> I use following code to update a textbox when a date has been chosen > >>> from my MonthCalendar. > >>> Since 6 textboxes use the same MonthCalendar I need to tell him > >>> which textbox was used. > >>> Therefore I have the variable: sWhichDateBox. > > >> Is there a reason why you don't declare "WhichDateBox As Textbox"? > > >> Armin > > > That didn't work either. > > What does not work? What did you try? More information, please. > > Armin That will bring up a new textbox on the form instead of using the existing one. Private Sub CreateDTP() Dim t As New TextBox t.Name = sDateBox 't = DirectCast(m_Controls.Item(sDateBox), TextBox) bCalOpened = True m_picker = New MonthCalendar m_picker.BringToFront() m_picker.MaxSelectionCount = 1 m_picker.Size = t.Size m_picker.BackColor = Color.Beige t.Parent = Me Me.Controls.Add(m_picker) m_picker.BringToFront() m_picker.Select() End Sub Private Sub m_picker_DateChanged(ByVal sender As Object, _ ByVal e As DateRangeEventArgs) Handles m_picker.DateChanged Dim hti As MonthCalendar.HitTestInfo = m_picker.HitTest (m_picker.PointToClient(MousePosition)) Dim t As New TextBox 'Dim t As TextBox = DirectCast(m_Controls.Item(iDateBox), TextBox) 'Display the Start and End property values of 'the SelectionRange object in the text boxes. t.Text = m_picker.SelectionRange.Start.Date.ToShortDateString () t.Text = m_picker.SelectionRange.End.Date.ToShortDateString() 'if we clicked on a date then hide the Calendar If hti.HitArea = MonthCalendar.HitArea.Date Then m_picker.Hide() Me.Controls.Remove(m_picker) m_picker = Nothing bCalOpened = False t.Dispose() End If End Sub Marco Co wrote:
Show quoteHide quote > On 23 mei, 20:32, "Armin Zingler" <az.nos***@freenet.de> wrote: You did not really read my post, did you? I asked why you don't declare >> Co wrote: >> >>>>> I use following code to update a textbox when a date has been >>>>> chosen from my MonthCalendar. >>>>> Since 6 textboxes use the same MonthCalendar I need to tell him >>>>> which textbox was used. >>>>> Therefore I have the variable: sWhichDateBox. >> >>>> Is there a reason why you don't declare "WhichDateBox As Textbox"? >> >>>> Armin >> >>> That didn't work either. >> >> What does not work? What did you try? More information, please. >> >> Armin > > I can only create a New textbox. > That will bring up a new textbox on the form instead of using the > existing one. "WhichDateBox As Textbox". Now you removed it completely. Armin
Show quote
Hide quote
On 23 mei, 22:00, "Armin Zingler" <az.nos***@freenet.de> wrote: I didn't remove it just renamed it:> Co wrote: > > On 23 mei, 20:32, "Armin Zingler" <az.nos***@freenet.de> wrote: > >> Co wrote: > > >>>>> I use following code to update a textbox when a date has been > >>>>> chosen from my MonthCalendar. > >>>>> Since 6 textboxes use the same MonthCalendar I need to tell him > >>>>> which textbox was used. > >>>>> Therefore I have the variable: sWhichDateBox. > > >>>> Is there a reason why you don't declare "WhichDateBox As Textbox"? > > >>>> Armin > > >>> That didn't work either. > > >> What does not work? What did you try? More information, please. > > >> Armin > > > I can only create a New textbox. > > That will bring up a new textbox on the form instead of using the > > existing one. > > You did not really read my post, did you? I asked why you don't declare > "WhichDateBox As Textbox". Now you removed it completely. > > Armin Dim sDateBox As TextBox Marco Co wrote:
Show quoteHide quote > On 23 mei, 22:00, "Armin Zingler" <az.nos***@freenet.de> wrote: Yes, but in your first post you were referring to 'sWhichDateBox'. It is not>> Co wrote: >>> On 23 mei, 20:32, "Armin Zingler" <az.nos***@freenet.de> wrote: >>>> Co wrote: >> >>>>>>> I use following code to update a textbox when a date has been >>>>>>> chosen from my MonthCalendar. >>>>>>> Since 6 textboxes use the same MonthCalendar I need to tell him >>>>>>> which textbox was used. >>>>>>> Therefore I have the variable: sWhichDateBox. >> >>>>>> Is there a reason why you don't declare "WhichDateBox As >>>>>> Textbox"? >> >>>>>> Armin >> >>>>> That didn't work either. >> >>>> What does not work? What did you try? More information, please. >> >>>> Armin >> >>> I can only create a New textbox. >>> That will bring up a new textbox on the form instead of using the >>> existing one. >> >> You did not really read my post, did you? I asked why you don't >> declare "WhichDateBox As Textbox". Now you removed it completely. >> >> Armin > > I didn't remove it just renamed it: > Dim sDateBox As TextBox a local variable. Therefore I had to assume it is declared at class level. I don't see it in your latest code. In Sub CreateDTP, you use 'sDateBox' now. I can not see where it is declared - probably a field in the class - and which value you assign. Anyway, if sDateBox is the Textbox in question, I don't know why you create a new Textbox instead of just using sDateBox. Armin
Show quote
Hide quote
On 24 mei, 02:27, "Armin Zingler" <az.nos***@freenet.de> wrote: That's what I couldn't get done.> Co wrote: > > On 23 mei, 22:00, "Armin Zingler" <az.nos***@freenet.de> wrote: > >> Co wrote: > >>> On 23 mei, 20:32, "Armin Zingler" <az.nos***@freenet.de> wrote: > >>>> Co wrote: > > >>>>>>> I use following code to update a textbox when a date has been > >>>>>>> chosen from my MonthCalendar. > >>>>>>> Since 6 textboxes use the same MonthCalendar I need to tell him > >>>>>>> which textbox was used. > >>>>>>> Therefore I have the variable: sWhichDateBox. > > >>>>>> Is there a reason why you don't declare "WhichDateBox As > >>>>>> Textbox"? > > >>>>>> Armin > > >>>>> That didn't work either. > > >>>> What does not work? What did you try? More information, please. > > >>>> Armin > > >>> I can only create a New textbox. > >>> That will bring up a new textbox on the form instead of using the > >>> existing one. > > >> You did not really read my post, did you? I asked why you don't > >> declare "WhichDateBox As Textbox". Now you removed it completely. > > >> Armin > > > I didn't remove it just renamed it: > > Dim sDateBox As TextBox > > Yes, but in your first post you were referring to 'sWhichDateBox'. It is not > a local variable. Therefore I had to assume it is declared at class level. I > don't see it in your latest code. In Sub CreateDTP, you use 'sDateBox' now. > I can not see where it is declared - probably a field in the class - and > which value you assign. > > Anyway, if sDateBox is the Textbox in question, I don't know why you create > a new Textbox instead of just using sDateBox. > > Armin How would that look Armin? Marco Co wrote:
Show quoteHide quote > On 24 mei, 02:27, "Armin Zingler" <az.nos***@freenet.de> wrote: I don't know _what_ you couldn't get done. Could you please be a bit more >> Co wrote: >>> On 23 mei, 22:00, "Armin Zingler" <az.nos***@freenet.de> wrote: >>>> Co wrote: >>>>> On 23 mei, 20:32, "Armin Zingler" <az.nos***@freenet.de> wrote: >>>>>> Co wrote: >> >>>>>>>>> I use following code to update a textbox when a date has been >>>>>>>>> chosen from my MonthCalendar. >>>>>>>>> Since 6 textboxes use the same MonthCalendar I need to tell >>>>>>>>> him which textbox was used. >>>>>>>>> Therefore I have the variable: sWhichDateBox. >> >>>>>>>> Is there a reason why you don't declare "WhichDateBox As >>>>>>>> Textbox"? >> >>>>>>>> Armin >> >>>>>>> That didn't work either. >> >>>>>> What does not work? What did you try? More information, please. >> >>>>>> Armin >> >>>>> I can only create a New textbox. >>>>> That will bring up a new textbox on the form instead of using the >>>>> existing one. >> >>>> You did not really read my post, did you? I asked why you don't >>>> declare "WhichDateBox As Textbox". Now you removed it completely. >> >>>> Armin >> >>> I didn't remove it just renamed it: >>> Dim sDateBox As TextBox >> >> Yes, but in your first post you were referring to 'sWhichDateBox'. >> It is not a local variable. Therefore I had to assume it is declared >> at class level. I don't see it in your latest code. In Sub >> CreateDTP, you use 'sDateBox' now. I can not see where it is >> declared - probably a field in the class - and which value you >> assign. >> >> Anyway, if sDateBox is the Textbox in question, I don't know why you >> create a new Textbox instead of just using sDateBox. >> >> Armin > > That's what I couldn't get done. > How would that look Armin? precise? :-) Ok, back the start: What I understood is that you have several textboxes. For which reason ever, you want to assign the value from a DateTimePicker to one of the Textboxes. First you want to memorize a certain Textbox in a variable. Later, in the DTP's DateChanged event, you want to assign the value to the Textbox that you've memorized in the variable. Is this correct? You first used a String to store the name of the Textbox in question. I suggested to use a variable of type Textbox instead. This enables you to directly use the variable instead of finding the Textbox by a String. Therefore I currently don't know what's the problem. By saying "just using sDateBox" I meant, well, just use it like any other variable, for example in sDateBox.Text = m_picker.SelectionRange.Start.Date.ToShortDateString I do not know when you intend to set variable 'sDateBox'. Maybe in the Textbox' Enter or GotFocus event? I don't know. Is this the problem? Armin
Show quote
Hide quote
"Co" <vonclausow***@gmail.com> wrote in message It sounds to me like you have a datetime object that is being set or news:b333bfeb-e42a-4a05-a677-ead79316144d@z9g2000yqi.googlegroups.com... > Hi All, > > I use following code to update a textbox when a date has been chosen > from my MonthCalendar. > Since 6 textboxes use the same MonthCalendar I need to tell him which > textbox was used. > Therefore I have the variable: sWhichDateBox. > How can I use that string to become the name of a textbox: > SelectedTextBox.Text = > m_picker.SelectionRange.Start.Date.ToShortDateString() > > > Private Sub m_picker_DateChanged(ByVal sender As Object, _ > ByVal e As DateRangeEventArgs) Handles m_picker.DateChanged > > Dim hti As MonthCalendar.HitTestInfo = m_picker.HitTest > (m_picker.PointToClient(MousePosition)) > Dim SelectedTextBox As TextBox = Nothing > SelectedTextBox.Name = sWhichDateBox > 'Display the Start and End property values of > 'the SelectionRange object in the text boxes. > SelectedTextBox.Text = > m_picker.SelectionRange.Start.Date.ToShortDateString() > SelectedTextBox.Text = > m_picker.SelectionRange.End.Date.ToShortDateString() > > 'if we clicked on a date then hide the Calendar > If hti.HitArea = MonthCalendar.HitArea.Date Then > m_picker.Hide() > SelectedTextBox.Parent.Controls.Remove(m_picker) > m_picker = Nothing > bCalOpened = False > End If > End Sub > > Regards > Marco > The Netherlands displayed by the calander control as well as the six text boxes. If this is the case, why aren't all six text boxes just updated with the new datetime from the calander? Either you are making this too complicated or, more likely, I'm over simplifying your issue. -- Mike
Show quote
Hide quote
On 23 mei, 19:43, "Family Tree Mike" <FamilyTreeM***@ThisOldHouse.com> It's a search form with six textboxes holding dates.wrote: > "Co" <vonclausow***@gmail.com> wrote in message > > news:b333bfeb-e42a-4a05-a677-ead79316144d@z9g2000yqi.googlegroups.com... > > > > > Hi All, > > > I use following code to update a textbox when a date has been chosen > > from my MonthCalendar. > > Since 6 textboxes use the same MonthCalendar I need to tell him which > > textbox was used. > > Therefore I have the variable: sWhichDateBox. > > How can I use that string to become the name of a textbox: > > SelectedTextBox.Text = > > m_picker.SelectionRange.Start.Date.ToShortDateString() > > > Private Sub m_picker_DateChanged(ByVal sender As Object, _ > > ByVal e As DateRangeEventArgs) Handles m_picker.DateChanged > > > Dim hti As MonthCalendar.HitTestInfo = m_picker.HitTest > > (m_picker.PointToClient(MousePosition)) > > Dim SelectedTextBox As TextBox = Nothing > > SelectedTextBox.Name = sWhichDateBox > > 'Display the Start and End property values of > > 'the SelectionRange object in the text boxes. > > SelectedTextBox.Text = > > m_picker.SelectionRange.Start.Date.ToShortDateString() > > SelectedTextBox.Text = > > m_picker.SelectionRange.End.Date.ToShortDateString() > > > 'if we clicked on a date then hide the Calendar > > If hti.HitArea = MonthCalendar.HitArea.Date Then > > m_picker.Hide() > > SelectedTextBox.Parent.Controls.Remove(m_picker) > > m_picker = Nothing > > bCalOpened = False > > End If > > End Sub > > > Regards > > Marco > > The Netherlands > > It sounds to me like you have a datetime object that is being set or > displayed by the calander control as well as the six text boxes. If this is > the case, why aren't all six text boxes just updated with the new datetime > from the calander? Either you are making this too complicated or, more > likely, I'm over simplifying your issue. > > -- > Mike All can have different values. Marco Marco,
You can set the name of a textbox to another name, however that does not change the reference to that texbox object. In other words, you don't make it dynamic like that. When you want to use it a little bit more dynamic then look at that samples I have given you some time ago but it did not fit you then (it was for another reason) Dim TextBoxes as Textbox() = {Textbox1,Textbo2 tot 6 } Now you can use it dynamically by just using the TextBoxes with its number from 0 to 5 Cor Show quoteHide quote "Co" <vonclausow***@gmail.com> wrote in message news:b333bfeb-e42a-4a05-a677-ead79316144d@z9g2000yqi.googlegroups.com... > Hi All, > > I use following code to update a textbox when a date has been chosen > from my MonthCalendar. > Since 6 textboxes use the same MonthCalendar I need to tell him which > textbox was used. > Therefore I have the variable: sWhichDateBox. > How can I use that string to become the name of a textbox: > SelectedTextBox.Text = > m_picker.SelectionRange.Start.Date.ToShortDateString() > > > Private Sub m_picker_DateChanged(ByVal sender As Object, _ > ByVal e As DateRangeEventArgs) Handles m_picker.DateChanged > > Dim hti As MonthCalendar.HitTestInfo = m_picker.HitTest > (m_picker.PointToClient(MousePosition)) > Dim SelectedTextBox As TextBox = Nothing > SelectedTextBox.Name = sWhichDateBox > 'Display the Start and End property values of > 'the SelectionRange object in the text boxes. > SelectedTextBox.Text = > m_picker.SelectionRange.Start.Date.ToShortDateString() > SelectedTextBox.Text = > m_picker.SelectionRange.End.Date.ToShortDateString() > > 'if we clicked on a date then hide the Calendar > If hti.HitArea = MonthCalendar.HitArea.Date Then > m_picker.Hide() > SelectedTextBox.Parent.Controls.Remove(m_picker) > m_picker = Nothing > bCalOpened = False > End If > End Sub > > Regards > Marco > The Netherlands
Show quote
Hide quote
On 23 mei, 21:29, "Cor Ligthert[MVP]" <Notmyfirstn***@planet.nl> I worked it out.wrote: > Marco, > > You can set the name of a textbox to another name, however that does not > change the reference to that texbox object. > > In other words, you don't make it dynamic like that. > When you want to use it a little bit more dynamic then look at that samples > I have given you some time ago but it did not fit you then (it was for > another reason) > > Dim TextBoxes as Textbox() = {Textbox1,Textbo2 tot 6 } > > Now you can use it dynamically by just using the TextBoxes with its number > from 0 to 5 > > Cor > > "Co" <vonclausow***@gmail.com> wrote in message > > news:b333bfeb-e42a-4a05-a677-ead79316144d@z9g2000yqi.googlegroups.com... > > > Hi All, > > > I use following code to update a textbox when a date has been chosen > > from my MonthCalendar. > > Since 6 textboxes use the same MonthCalendar I need to tell him which > > textbox was used. > > Therefore I have the variable: sWhichDateBox. > > How can I use that string to become the name of a textbox: > > SelectedTextBox.Text = > > m_picker.SelectionRange.Start.Date.ToShortDateString() > > > Private Sub m_picker_DateChanged(ByVal sender As Object, _ > > ByVal e As DateRangeEventArgs) Handles m_picker.DateChanged > > > Dim hti As MonthCalendar.HitTestInfo = m_picker.HitTest > > (m_picker.PointToClient(MousePosition)) > > Dim SelectedTextBox As TextBox = Nothing > > SelectedTextBox.Name = sWhichDateBox > > 'Display the Start and End property values of > > 'the SelectionRange object in the text boxes. > > SelectedTextBox.Text = > > m_picker.SelectionRange.Start.Date.ToShortDateString() > > SelectedTextBox.Text = > > m_picker.SelectionRange.End.Date.ToShortDateString() > > > 'if we clicked on a date then hide the Calendar > > If hti.HitArea = MonthCalendar.HitArea.Date Then > > m_picker.Hide() > > SelectedTextBox.Parent.Controls.Remove(m_picker) > > m_picker = Nothing > > bCalOpened = False > > End If > > End Sub > > > Regards > > Marco > > The Netherlands Dim sDateBox As TextBox Private Sub tbVerlooptTot_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tbVerlooptTot.DoubleClick If bCalOpened = False Then sDateBox = tbVerlooptTot CreateDTP() End If Private Sub CreateDTP() bCalOpened = True m_picker = New MonthCalendar m_picker.BringToFront() m_picker.MaxSelectionCount = 1 m_picker.Size = tbVerlooptTot.Size m_picker.BackColor = Color.Beige tbVerlooptTot.Parent = Me Me.Controls.Add(m_picker) m_picker.BringToFront() m_picker.Select() End Sub Private Sub m_picker_DateChanged(ByVal sender As Object, _ ByVal e As DateRangeEventArgs) Handles m_picker.DateChanged Dim hti As MonthCalendar.HitTestInfo = m_picker.HitTest (m_picker.PointToClient(MousePosition)) Dim t As TextBox = DirectCast(sDateBox, TextBox) 'Display the Start and End property values of 'the SelectionRange object in the text boxes. t.Text = m_picker.SelectionRange.Start.Date.ToShortDateString () t.Text = m_picker.SelectionRange.End.Date.ToShortDateString() 'if we clicked on a date then hide the Calendar If hti.HitArea = MonthCalendar.HitArea.Date Then m_picker.Hide() Me.Controls.Remove(m_picker) m_picker = Nothing bCalOpened = False End If End Sub Thanks for helping me in the right direction. Marco On Sat, 23 May 2009 12:36:36 -0700 (PDT), Co <vonclausow***@gmail.com>
wrote: Show quoteHide quote >On 23 mei, 21:29, "Cor Ligthert[MVP]" <Notmyfirstn***@planet.nl> It looks like you have six DoubleClick event routines. You should>wrote: >> Marco, >> >> You can set the name of a textbox to another name, however that does not >> change the reference to that texbox object. >> >> In other words, you don't make it dynamic like that. >> When you want to use it a little bit more dynamic then look at that samples >> I have given you some time ago but it did not fit you then (it was for >> another reason) >> >> Dim TextBoxes as Textbox() = {Textbox1,Textbo2 tot 6 } >> >> Now you can use it dynamically by just using the TextBoxes with its number >> from 0 to 5 >> >> Cor >> >> "Co" <vonclausow***@gmail.com> wrote in message >> >> news:b333bfeb-e42a-4a05-a677-ead79316144d@z9g2000yqi.googlegroups.com... >> >> > Hi All, >> >> > I use following code to update a textbox when a date has been chosen >> > from my MonthCalendar. >> > Since 6 textboxes use the same MonthCalendar I need to tell him which >> > textbox was used. >> > Therefore I have the variable: sWhichDateBox. >> > How can I use that string to become the name of a textbox: >> > SelectedTextBox.Text = >> > m_picker.SelectionRange.Start.Date.ToShortDateString() >> >> > Private Sub m_picker_DateChanged(ByVal sender As Object, _ >> > ByVal e As DateRangeEventArgs) Handles m_picker.DateChanged >> >> > Dim hti As MonthCalendar.HitTestInfo = m_picker.HitTest >> > (m_picker.PointToClient(MousePosition)) >> > Dim SelectedTextBox As TextBox = Nothing >> > SelectedTextBox.Name = sWhichDateBox >> > 'Display the Start and End property values of >> > 'the SelectionRange object in the text boxes. >> > SelectedTextBox.Text = >> > m_picker.SelectionRange.Start.Date.ToShortDateString() >> > SelectedTextBox.Text = >> > m_picker.SelectionRange.End.Date.ToShortDateString() >> >> > 'if we clicked on a date then hide the Calendar >> > If hti.HitArea = MonthCalendar.HitArea.Date Then >> > m_picker.Hide() >> > SelectedTextBox.Parent.Controls.Remove(m_picker) >> > m_picker = Nothing >> > bCalOpened = False >> > End If >> > End Sub >> >> > Regards >> > Marco >> > The Netherlands > >I worked it out. > >Dim sDateBox As TextBox > >Private Sub tbVerlooptTot_DoubleClick(ByVal sender As Object, ByVal e >As System.EventArgs) Handles tbVerlooptTot.DoubleClick > If bCalOpened = False Then > sDateBox = tbVerlooptTot > CreateDTP() > End If > >Private Sub CreateDTP() > > bCalOpened = True > m_picker = New MonthCalendar > m_picker.BringToFront() > m_picker.MaxSelectionCount = 1 > m_picker.Size = tbVerlooptTot.Size > m_picker.BackColor = Color.Beige > tbVerlooptTot.Parent = Me > Me.Controls.Add(m_picker) > m_picker.BringToFront() > m_picker.Select() > > End Sub > > Private Sub m_picker_DateChanged(ByVal sender As Object, _ > ByVal e As DateRangeEventArgs) Handles m_picker.DateChanged > > Dim hti As MonthCalendar.HitTestInfo = m_picker.HitTest >(m_picker.PointToClient(MousePosition)) > Dim t As TextBox = DirectCast(sDateBox, TextBox) > > 'Display the Start and End property values of > 'the SelectionRange object in the text boxes. > t.Text = m_picker.SelectionRange.Start.Date.ToShortDateString >() > t.Text = m_picker.SelectionRange.End.Date.ToShortDateString() > > 'if we clicked on a date then hide the Calendar > If hti.HitArea = MonthCalendar.HitArea.Date Then > m_picker.Hide() > Me.Controls.Remove(m_picker) > m_picker = Nothing > bCalOpened = False > End If > End Sub > >Thanks for helping me in the right direction. > >Marco have only one that handles the DoubleClick events from all of the textboxes. It is not necessary to have bCalOpened, use sDateBox instead. CreateDTP is hard coded to use one textbox. Why does CreateDTP set the Size of the MonthCalendar to match the textbox Size? I would think you would want to leave the size alone and set the Location to something like New Point(sDateBox.Left, sDateBox.Bottom + 5). Private sDateBox As TextBox = Nothing Private Sub tbVerlooptTot_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tbVerlooptTot.DoubleClick, ... If sDateBox Is Nothing Then sDateBox = DirectCast(sender, TextBox) m_picker = New MonthCalendar m_picker.BringToFront() m_picker.MaxSelectionCount = 1 m_picker.Size = sDateBox.Size m_picker.BackColor = Color.Beige Me.Controls.Add(m_picker) m_picker.BringToFront() m_picker.Select() End If End Sub
treeview in windowsdialog
Call button click event Visual Studio 2008 and Classes Inheriting From System.Web.UI.WebControls.Style Problem with embedded carriage returns trouble reading word documents Good tutorial for working with XML Using function with PChar data type still problems reading word documents... how to know if to close sqlreader Build Number - how to auto increment? |
|||||||||||||||||||||||