pb with .selectedvalue of a combobox

S

Sam

Hi,

In this code my combobox is properly filled with all the records in my
dataset. But when I want to set it to a value using selectedvalue, it
just don't work as cboViewTable.SelectedValue will always be equal to
Nothing, although ds.Tables(0).Rows(m_curRow).Item("ViewTable") is
equal to "string1"
What's wrong with this code ?


with cboViewTable
.DataSource = m_frmFields.Control.Tables(3)
.DisplayMember = "table_name"
.ValueMember = "table_name"
End With

cboViewTable.SelectedValue =
ds.Tables(0).Rows(m_curRow).Item("ViewTable")

Thx
 
S

Sam

Actually I got a weird problem in the same kind. Below if i select a
value in my first combo, it will also set the second combo to the same
value. I know they have the same datsource, but they should be
independent ! What's wrong there?

With cboViewTable
.DataSource = m_frmFields.Control.Tables(3)
.DisplayMember = "table_name"
.ValueMember = "table_name"
End With

With cboInsertTable
.DataSource = m_frmFields.Control.Tables(3)
.DisplayMember = "table_name"
.ValueMember = "table_name"
End With
 
S

Sam

Actually I believe since they have the same datasource so they point to
the same memory location. That's why when I modify one, the other one
is modified too. But how can i assign them the same datasource then ?
Like I would for the different column of a datagrid....
 
C

Cor Ligthert

Sam,

It are two different problems.
Use for the cboViewTable. the selected index that you find with
cboViewTable.FindString or FindStringExact.

To let more controls go not synchonize you have to use seperated dataviews
from the same table as a datasource..

I hope this helps,

Cor
 
S

Sam

I've made a copy of my datatable insead, using Copy. It works, if this
correct ?

I don't understand your first sentence, sorry

thx
 
C

Cor Ligthert

Sam,

Use a dataview as datasource not a copy of your datatable.

dim dv1 as new Dataview(mydatatable)
dim dv2 as new Dataview(mydatatable)

Combo1.datasource = dv1
Combo2.datasource = dv2

Cor
 
C

Cor Ligthert

Sam

cmb.selectedindex = cmb.findstringexact("myname")

This is as well the way to make such an autokey combobox.

I hope this helps,

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top