Issue related to combobox....

Please support our VB.NET advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
Reply

Join Date: Jun 2005
Posts: 9
Reputation: vrushalinz1 is an unknown quantity at this point 
Solved Threads: 0
vrushalinz1 vrushalinz1 is offline Offline
Newbie Poster

Issue related to combobox....

 
0
  #1
Jul 5th, 2005
hi,

I have used a combobox to display a list of options like 1 Month,2 Months,3 Months and last option Other.
Wen i click on "Other" , calender opens and i have to select the date.
The problem is after i select the date and the calender closes i am unable to set the combobox1.text property to the date i selected.
[i am taking the date selected in the global variable].
Please help me with this. :-|

Thanks in advance
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 41
Reputation: npasma is an unknown quantity at this point 
Solved Threads: 0
npasma's Avatar
npasma npasma is offline Offline
Light Poster

Re: Issue related to combobox....

 
0
  #2
Jul 7th, 2005
Could I see some code? Maybe post some in code tags? Thanks.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 9
Reputation: vrushalinz1 is an unknown quantity at this point 
Solved Threads: 0
vrushalinz1 vrushalinz1 is offline Offline
Newbie Poster

Re: Issue related to combobox....

 
0
  #3
Jul 8th, 2005
HI,

Here is the code u asked for,

Private Sub cboExpiryDate_SelectedIndexChanged(ByVal sender As_ System.Object, ByVal e As System.EventArgs) Handles_ cboExpiryDate.SelectedIndexChanged

If cboExpiryDate.Text = "1 Month" Then
'do something
elseif cboExpiryDate.Text = "2 Month" Then
'do something
elseif cboExpiryDate.Text = "3 Month" Then
'do something
ElseIf cboExpiryDate.Text = "Other" Then
'Open a calender and receive the date in a variable m_strExpDate
' i was trying to do as below but wit no results.
cboExpiryDate.Text =m_strExpDate

End Sub
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 65
Reputation: cpopham is an unknown quantity at this point 
Solved Threads: 0
cpopham cpopham is offline Offline
Junior Poster in Training

Re: Issue related to combobox....

 
0
  #4
Jul 8th, 2005
Are you setting the m_strExpDate vairable to the date the user selected on the calender?

Chester

Originally Posted by vrushalinz1
HI,

Here is the code u asked for,

Private Sub cboExpiryDate_SelectedIndexChanged(ByVal sender As_ System.Object, ByVal e As System.EventArgs) Handles_ cboExpiryDate.SelectedIndexChanged

If cboExpiryDate.Text = "1 Month" Then
'do something
elseif cboExpiryDate.Text = "2 Month" Then
'do something
elseif cboExpiryDate.Text = "3 Month" Then
'do something
ElseIf cboExpiryDate.Text = "Other" Then
'Open a calender and receive the date in a variable m_strExpDate
' i was trying to do as below but wit no results.
cboExpiryDate.Text =m_strExpDate

End Sub
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 9
Reputation: vrushalinz1 is an unknown quantity at this point 
Solved Threads: 0
vrushalinz1 vrushalinz1 is offline Offline
Newbie Poster

Re: Issue related to combobox....

 
0
  #5
Jul 9th, 2005
Originally Posted by cpopham
Are you setting the m_strExpDate vairable to the date the user selected on the calender?

Chester
hi,

Yes i assigned the date to the m_strExpDate vairable and tried to display it in the textarea of the combo box.
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 175
Reputation: Letscode is an unknown quantity at this point 
Solved Threads: 6
Letscode's Avatar
Letscode Letscode is offline Offline
Junior Poster

Re: Issue related to combobox....

 
0
  #6
Jul 13th, 2005
From your code I see that you are not adding the date chosen to the combobox.

You gotta do two things

1.You should ADD the string to the combo box.To be honest with you,I dont know how to handle combo box,I was thinking combo box and dropdownlist are the same until I read your post and I saw you using something like cboExpiryDate.Text which is not possible in dropdownlist.

In a dropdownlist you can add a new item to the webcontrol by using something like

DropDownList1.Items.Add("My value")

or in your case

DropDownList1.Items.Add(m_strExpDate)

2.Then you gotta ASSIGN the value to the webcontrol by using something like this.

DropDownList1.SelectedItem.Text = m_strExpDate

Hope it helps.
Save White Tiger
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 9
Reputation: vrushalinz1 is an unknown quantity at this point 
Solved Threads: 0
vrushalinz1 vrushalinz1 is offline Offline
Newbie Poster

Re: Issue related to combobox....

 
0
  #7
Jul 14th, 2005
Originally Posted by Letscode
From your code I see that you are not adding the date chosen to the combobox.

You gotta do two things

1.You should ADD the string to the combo box.To be honest with you,I dont know how to handle combo box,I was thinking combo box and dropdownlist are the same until I read your post and I saw you using something like cboExpiryDate.Text which is not possible in dropdownlist.

In a dropdownlist you can add a new item to the webcontrol by using something like

DropDownList1.Items.Add("My value")

or in your case

DropDownList1.Items.Add(m_strExpDate)

2.Then you gotta ASSIGN the value to the webcontrol by using something like this.

DropDownList1.SelectedItem.Text = m_strExpDate

Hope it helps.


Oh thanks a lot, But to be honest i tried with this after i posted this on this forum and got the results. BUt from ur reply i gotto know that v need to add the item first to the list before assigning it to the text area which i was not doin before.

Anyways thanks a lot.
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 3
Reputation: Jason Barnett is an unknown quantity at this point 
Solved Threads: 0
Jason Barnett Jason Barnett is offline Offline
Newbie Poster

Re: Issue related to combobox....

 
0
  #8
Oct 25th, 2005
I think I may have a similar issue, but I am searching for a different solution.

I'm using VB.NET 2005 (beta) and I'm trying to assign a value to a Combobox's Text property during a SelectedIndexChanged event. I've placed a ComboBox on a form without changing any of its properties and added the following code:
  1. Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
  2. If ComboBox1.SelectedIndex = 0 Then
  3. ComboBox1.Text = "Value retrieved from some function"
  4. End If
  5. End Sub
  6.  
  7. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  8. ComboBox1.Items.Add("Other")
  9. ComboBox1.Text = "Select an item"
  10. End Sub
I first noticed that "Select an item" appears fine, even though it's not added as an item. However, "Value retrieved..." does not appear when "Other" is selected from the dropdownlist. When stepping through the code, the value of ComboBox1.Text is "Value retrieved...", but when SelectedIndexChanged completes the ComboBox reads "Other".

I know this could be done in VB6. Is this a bug with VB.NET? With VS 2005? Or am I doing something wrong?
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 3
Reputation: Jason Barnett is an unknown quantity at this point 
Solved Threads: 0
Jason Barnett Jason Barnett is offline Offline
Newbie Poster

Re: Issue related to combobox....

 
0
  #9
Nov 4th, 2005
I believe I may have come up with a solution, following these steps:
  • I subclassed the ComboBox and implemented IMessageFilter.
  • I set a flag when SelectionChangeCommitted fires.
  • Then I filter for a Paint event and fire a custom event.

If anyone has a better solution, please let me know. In the meantime, here is an example:

Derived Class:
  1. Public Class MyComboBox
  2. Inherits ComboBox
  3. Implements IMessageFilter
  4.  
  5. Private Const WM_PAINT As Integer = &HF
  6.  
  7. Private iSelectChangeCommit As Boolean = False
  8.  
  9. ''' <summary>
  10. ''' Fires when a selection change has completed and before the control is
  11. ''' painted.
  12. ''' </summary>
  13. Public Event SelectionChangeComplete(ByVal sender As Object, ByVal e As System.EventArgs)
  14.  
  15. Public Sub New()
  16. Application.AddMessageFilter(Me)
  17. End Sub
  18.  
  19. Private Sub MyComboBox_SelectionChangeCommitted(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.SelectionChangeCommitted
  20. iSelectChangeCommit = True
  21. End Sub
  22.  
  23. Private Function PreFilterMessage(ByRef m As System.Windows.Forms.Message) As Boolean Implements System.Windows.Forms.IMessageFilter.PreFilterMessage
  24. If m.Msg = WM_PAINT AndAlso iSelectChangeCommit Then
  25. RaiseEvent SelectionChangeComplete(Me, Nothing)
  26. Me.SelectionStart = 0
  27. Me.SelectionLength = Len(Me.Text)
  28. iSelectChangeCommit = False
  29. End If
  30. End Function
  31.  
  32. End Class
Form Code:
  1. Public Class Form1
  2.  
  3. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  4. ComboBox1.Items.Add("Other...")
  5. ComboBox1.Text = "Select an item"
  6. End Sub
  7.  
  8. Private Sub ComboBox1_SelectionChangeComplete(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectionChangeComplete
  9. ComboBox1.Text = "A Value"
  10. End Sub
  11.  
  12. End Class
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 3
Reputation: Jason Barnett is an unknown quantity at this point 
Solved Threads: 0
Jason Barnett Jason Barnett is offline Offline
Newbie Poster

Re: Issue related to combobox....

 
0
  #10
Nov 11th, 2005
I found a bug in my code...

With a recent project, I received multiple WM_PAINT messages before the iSelectChangeCommit variable was reset. This caused an infinite loop, raising SelectionChangeComplete continuously. The following code reflects the correct order of operations (Note that I reset the variable as soon as I enter the If block).

  1. If m.Msg = WM_PAINT AndAlso iSelectChangeCommit Then
  2. iSelectChangeCommit = False
  3. RaiseEvent SelectionChangeComplete(Me, Nothing)
  4. Me.SelectionStart = 0
  5. Me.SelectionLength = Len(Me.Text)
  6. End If

Hope this hasn't caused anyone grief when trying to implement my solution.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the VB.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC