| | |
Issue related to combobox....
Please support our VB.NET advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
![]() |
•
•
Join Date: Jun 2005
Posts: 9
Reputation:
Solved Threads: 0
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
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
•
•
Join Date: Jun 2005
Posts: 9
Reputation:
Solved Threads: 0
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
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
•
•
Join Date: Mar 2005
Posts: 65
Reputation:
Solved Threads: 0
Are you setting the m_strExpDate vairable to the date the user selected on the calender?
Chester
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
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.
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
•
•
Join Date: Jun 2005
Posts: 9
Reputation:
Solved Threads: 0
•
•
•
•
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.
•
•
Join Date: Oct 2005
Posts: 3
Reputation:
Solved Threads: 0
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:
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?
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:
VB.NET Syntax (Toggle Plain Text)
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged If ComboBox1.SelectedIndex = 0 Then ComboBox1.Text = "Value retrieved from some function" End If End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ComboBox1.Items.Add("Other") ComboBox1.Text = "Select an item" End Sub
I know this could be done in VB6. Is this a bug with VB.NET? With VS 2005? Or am I doing something wrong?
•
•
Join Date: Oct 2005
Posts: 3
Reputation:
Solved Threads: 0
I believe I may have come up with a solution, following these steps:
If anyone has a better solution, please let me know. In the meantime, here is an example:
Derived Class:
Form Code:
- 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:
VB.NET Syntax (Toggle Plain Text)
Public Class MyComboBox Inherits ComboBox Implements IMessageFilter Private Const WM_PAINT As Integer = &HF Private iSelectChangeCommit As Boolean = False ''' <summary> ''' Fires when a selection change has completed and before the control is ''' painted. ''' </summary> Public Event SelectionChangeComplete(ByVal sender As Object, ByVal e As System.EventArgs) Public Sub New() Application.AddMessageFilter(Me) End Sub Private Sub MyComboBox_SelectionChangeCommitted(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.SelectionChangeCommitted iSelectChangeCommit = True End Sub Private Function PreFilterMessage(ByRef m As System.Windows.Forms.Message) As Boolean Implements System.Windows.Forms.IMessageFilter.PreFilterMessage If m.Msg = WM_PAINT AndAlso iSelectChangeCommit Then RaiseEvent SelectionChangeComplete(Me, Nothing) Me.SelectionStart = 0 Me.SelectionLength = Len(Me.Text) iSelectChangeCommit = False End If End Function End Class
VB.NET Syntax (Toggle Plain Text)
Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ComboBox1.Items.Add("Other...") ComboBox1.Text = "Select an item" End Sub Private Sub ComboBox1_SelectionChangeComplete(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectionChangeComplete ComboBox1.Text = "A Value" End Sub End Class
•
•
Join Date: Oct 2005
Posts: 3
Reputation:
Solved Threads: 0
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).
Hope this hasn't caused anyone grief when trying to implement my solution.
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).
VB.NET Syntax (Toggle Plain Text)
If m.Msg = WM_PAINT AndAlso iSelectChangeCommit Then iSelectChangeCommit = False RaiseEvent SelectionChangeComplete(Me, Nothing) Me.SelectionStart = 0 Me.SelectionLength = Len(Me.Text) End If
Hope this hasn't caused anyone grief when trying to implement my solution.
![]() |
Other Threads in the VB.NET Forum
- Previous Thread: my code doest work
- Next Thread: How do i save values of text boxes to database?
| Thread Tools | Search this Thread |
"crystal .net .net2005 .net2008 30minutes 2005 2008 access account arithmetic array basic button buttons center check code component connectionstring convert crystalreport data database databasesearch datagrid datagridview date design dissertation dissertations dissertationthesis dosconsolevb.net dropdownlist excel fade file-dialog filter firewall folder ftp generatetags hardcopy image images input insert intel math monitor navigate net networking opacity output panel passingparameters peertopeervideostreaming picturebox picturebox1 port printing problem problemwithinstallation project reports" savedialog searchvb.net select shutdown string survey tcp temperature text textbox timer timespan toolbox trim updown user useraccounts usercontrol vb vb.net vb.netcode vb.netformclosing()eventpictureboxmessagebox vb.nettoolboxvisualbasic2008sidebar vb2008 vbnet view visual visualbasic visualbasic.net visualstudio visualstudio2008 web winforms wpf year





