|
-
October 30th, 2006, 06:32 AM
#1
Combobox control
I use a combobox wherein the user may type his value or select from the dropdownlist. In this schenario, everytime when the user opens the form, I want the combobox control to reset/refresh (I mean no value should be displayed). Now I have my first value selected always. Please help me out. Thnx.
-
October 30th, 2006, 06:50 AM
#2
Re: Combobox control
in form load event u can clear the items in combobox
Code:
ComboBox1.Items.Clear
if u want the comboBox selectIndex reset
Code:
ComboBox1.SelectedIndex = -1
-
October 30th, 2006, 06:58 AM
#3
Re: Combobox control
This will just clear the box
-
October 30th, 2006, 07:36 AM
#4
Re: Combobox control
It's a Databound control. Then how do I go about?
-
October 30th, 2006, 08:02 AM
#5
Re: Combobox control
The the Form_Load event you will have something like the following code -
Code:
Me.MyTableTableAdapter.Fill(Me.MyDatabaseDataSet.MyTable)
Insert the instruction immediately after this, so you get -
Code:
Me.MyTableTableAdapter.Fill(Me.MyDatabaseDataSet.MyTable)
ComboBox1.Text = ""
-
October 30th, 2006, 08:24 AM
#6
Re: Combobox control
Am still not getting it. Am I doing anything wrong with the control's property?
-
October 30th, 2006, 08:36 AM
#7
Re: Combobox control
The only 2 properties I touched in the ComboBox were -
DataSource eg, MyDatabase.mdb - MyTable
DisplayMember - MyFieldName
-
October 30th, 2006, 08:51 AM
#8
Re: Combobox control
Am posting my sample code below. Please check that out.
-----------------------------------------------------------------------------------------------
Public Class Form2
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Close()
End Sub
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.MyTableTableAdapter.Fill(Me.MyDatabaseDataSet.MyTable)
ComboBox.Text = ""
End Sub
Private Sub ComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox.SelectedIndexChanged
'am doing some actions here.....
End Sub
End Class
-----------------------------------------------------------------------------------------------
-
October 30th, 2006, 08:57 AM
#9
Re: Combobox control
I would comment out everything except the Form Load event and see how that effects the result
Just leave this as an active event
Code:
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.MyTableTableAdapter.Fill(Me.MyDatabaseDataSet.MyTable)
ComboBox.Text = ""
End Sub
-
October 30th, 2006, 09:34 AM
#10
Re: Combobox control
It works fine. But after I type some value close the form and then reopen the form then the first value from the dropdownlist is getting displayed. Actually I want this control to be blank whenever I close and open the form. Hope am clear.
-
October 30th, 2006, 09:43 AM
#11
Re: Combobox control
Try shifting the instructions to the
Form1_Activated event
Code:
Private Sub Form2_Activated (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.MyTableTableAdapter.Fill(Me.MyDatabaseDataSet.MyTable)
ComboBox.Text = ""
End Sub
By doing this it should load and clear the combobox each time the form is activated (rather than just once - only when it is loaded the first time)
-
October 30th, 2006, 10:21 AM
#12
Re: Combobox control
No luck! It still displays the first value from the dropdownlist. Is it because of the actions that am doing inside the 'ComboBox_SelectedIndexChanged'. I have given below the complete and final code. I kindly request you to check out. Thank you.
************************************************************
Public Class Form2
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'This is Cancel button
Me.Close()
End Sub
Private Sub Form2_Activated(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.MyTableTableAdapter.Fill(Me.MyDatabaseDataSet.MyTable)
ComboBox.Text = ""
End Sub
Private Sub ComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox.SelectedIndexChanged
If (ComboBox.Text = "xxxx xxxx xxxx xxxx xxxx") Then
' .... am doing some actions here.....
End If
End Sub
End Class
-
October 30th, 2006, 01:18 PM
#13
Re: Combobox control
Use selected index property as combobox style is dropdownlist.
Code:
Public Class Form1
Dim conn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\attendence.mdb;Persist Security Info=False")
Dim dt As New DataTable
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim adapter As New OleDb.OleDbDataAdapter("SELECT * FROM student", conn)
conn.Open()
adapter.Fill(dt)
dt.TableName = "Student"
conn.Close()
ComboBox1.DataSource = dt
ComboBox1.DisplayMember = "rno"
ComboBox1.SelectedIndex = -1
End Sub
End Class
-
October 30th, 2006, 05:49 PM
#14
-
October 30th, 2006, 10:29 PM
#15
Re: Combobox control
Why do you need ?
Code:
Private Sub ComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox.SelectedIndexChanged
If (ComboBox.Text = "xxxx xxxx xxxx xxxx xxxx") Then
' .... am doing some actions here.....
End If
You tell me that if this event is not in the code then everything is fine -
So .... why do you need THIS event - I'm sure there are other ways to do what you are doing in THIS event
Also, you may like to explain what you are trying to achieve overall - there may be a better way to deal with your problem.
The fact you are having big problems with a rather basic control (ComboBox) indicates that you just may be trying to do something it was not designed to do
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|