difficult question autofilter

Astie

Active member
Joined
Oct 20, 2005
Messages
27
Location
Holland
Programming Experience
Beginner
Hello

i've got four you guys maybe an easy question but it is very difficult to explain. But i'll try.

I've got an MS Acces Database, ive got a table called tbl_codes2. In that table i've got 3 collumns: Id, Codes2 and Uren.

Now i've filled a Combobox with the data from column "Codes2".
The thing i want is that when i select something from the Combobox, i want the data on the same row but then from the Column "Uren" get showed in a label.

I know i can do this by an IF statement but i want al the data controled from the Database and not when something changes i have to change te source code.

When you not getting my question, be free to ask
 
sevenhalo said:
What tools are you using to bring the data into your application? Or is this being done entirely in Access?

i use visual studio 2003, and programming in vb.net. Or is this a studip answer?:confused:
 
No, not at all. The problem is, I think you're going to need to make a source code change in order for this to work. It's not a huge change (I wouldn't think it would be), but if you show us some of the source code you use to populate the combobox; we can help you pretty easily.
 
sevenhalo said:
No, not at all. The problem is, I think you're going to need to make a source code change in order for this to work. It's not a huge change (I wouldn't think it would be), but if you show us some of the source code you use to populate the combobox; we can help you pretty easily.

i'm doing that bij using the toolbox in visual studio.

the next thing i found in the region:

HTML:
'cb_codes2
'
Me.cb_codes2.AccessibleDescription = resources.GetString("cb_codes2.AccessibleDescription")
Me.cb_codes2.AccessibleName = resources.GetString("cb_codes2.AccessibleName")
Me.cb_codes2.Anchor = CType(resources.GetObject("cb_codes2.Anchor"), System.Windows.Forms.AnchorStyles)
Me.cb_codes2.BackgroundImage = CType(resources.GetObject("cb_codes2.BackgroundImage"), System.Drawing.Image)
Me.cb_codes2.DataSource = Me.ds_codes2.tbl_codes2
Me.cb_codes2.DisplayMember = "codes2"
Me.cb_codes2.Dock = CType(resources.GetObject("cb_codes2.Dock"), System.Windows.Forms.DockStyle)
Me.cb_codes2.DropDownWidth = 50
Me.cb_codes2.Enabled = CType(resources.GetObject("cb_codes2.Enabled"), Boolean)
Me.cb_codes2.Font = CType(resources.GetObject("cb_codes2.Font"), System.Drawing.Font)
Me.cb_codes2.ImeMode = CType(resources.GetObject("cb_codes2.ImeMode"), System.Windows.Forms.ImeMode)
Me.cb_codes2.IntegralHeight = CType(resources.GetObject("cb_codes2.IntegralHeight"), Boolean)
Me.cb_codes2.ItemHeight = CType(resources.GetObject("cb_codes2.ItemHeight"), Integer)
Me.cb_codes2.Location = CType(resources.GetObject("cb_codes2.Location"), System.Drawing.Point)
Me.cb_codes2.MaxDropDownItems = CType(resources.GetObject("cb_codes2.MaxDropDownItems"), Integer)
Me.cb_codes2.MaxLength = CType(resources.GetObject("cb_codes2.MaxLength"), Integer)
Me.cb_codes2.Name = "cb_codes2"
Me.cb_codes2.RightToLeft = CType(resources.GetObject("cb_codes2.RightToLeft"), System.Windows.Forms.RightToLeft)
Me.cb_codes2.Size = CType(resources.GetObject("cb_codes2.Size"), System.Drawing.Size)
Me.cb_codes2.TabIndex = CType(resources.GetObject("cb_codes2.TabIndex"), Integer)
Me.cb_codes2.Text = resources.GetString("cb_codes2.Text")
Me.cb_codes2.Visible = CType(resources.GetObject("cb_codes2.Visible"), Boolean)
 
oke i've looked at the code behind your example. But now i've got some questions.

I'm doing al the connection work within visual studio and not with coding like your work. I also using an oledbdataadapter and a dataset for my data. How can i make this work because my DS is filled when the form loads. And you are making an connection (in a why i dont understand) when you click the combobox. Can you maybe make it more "Editable" for me :D


HTML:
Dim strSQL As String
Dim con As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "/test.mdb; Persist Security Info=False;"
Dim oledbcon As New OleDbConnection(con)
Dim cmd As OleDbCommand
Dim objRead As OleDbDataReader
 
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
ComboBox2.SelectedIndex = ComboBox1.SelectedIndex
Me.lblExample1.Text = ComboBox2.Text
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
oledbcon.Open()
strSQL = "SELECT * FROM table1"
cmd = New OleDbCommand(strSQL, oledbcon)
objRead = cmd.ExecuteReader
While objRead.Read
ComboBox1.Items.Add(objRead("Codes2") & "")
cmbExample2.Items.Add(objRead("Codes2") & "")
ComboBox2.Items.Add(objRead("Uren") & "")
End While
objRead.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
oledbcon.Close()
End Try
End Sub
Private Sub cmbExample2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbExample2.SelectedIndexChanged
Try
oledbcon.Open()
strSQL = "SELECT Uren FROM table1 WHERE Codes2 = '" & cmbExample2.Text & "'"
cmd = New OleDbCommand(strSQL, oledbcon)
objRead = cmd.ExecuteReader
While objRead.Read
Me.lblExample2.Text = objRead("Uren") & ""
End While
objRead.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
oledbcon.Close()
End Try
End Sub
End Class
 
I sent you two examples with purpose. Now you know that you can either fetch the data at ones and then use a trick as we do it in example 1 (changing selected index of comboBox2 we change the text of label as well) .. or you can fetch the data each time you need to change label's text property (example 2). Both samples have an advantage and also disadvantage. You should decide which one best suits your needs.
Say, in this case you should go for way showed in example 1. Why you would open/close the connection each time you want to retrieve only small piece of data (only one word while total data are about 10 words)??? But what if you need to get bigger portion of data at ones? Then would be better if you implement the second example as if you try to fetch all the data at start and populate ComboBox and say ListView, ListBox ... at ones it will look very slow not because of reading data but because of populating the controls.

HTH
Regards ;)
 
Back
Top