Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Set a combobox selectedvalue problem

3 réponses
Avatar
sfauchille
Hello,

My Problem.


I have 2 classes
ClsEnterprise
ClsUser


The ClsEnterprise has property :
Id_Ent
Name
....


The ClsUser has property :
Id_User
Name
Id_Ent
....


and 2 others Classes
ClsEnterprises as list (of ClsEnterprise)
ClsUsers as list (of ClsUser)


I have 2 combo box
CboUser
CboEnterprise


To fill the combo
CboUser.DataSource = ClsUsers
CboUser.DisplayMenber ="Name"
CboUser.ValueMember = "IdUser


CboEnterprise.DataSource = ClsEnterprises
CboEnterprise.DisplayMenber ="Name"
CboEnterprise.ValueMember = "IdEnterprise


When I select an enterprise in the CboEnterprise I would like only to
show Users from this enterprise
How can i do???


I tried this but it doesn't work:
Dim Result = From Usr In Users() Where Usr.Id =
CboReseaux.ValueMember
CboUser.DataSource = Result

3 réponses

Avatar
Hi englishman,

Here, it's in French, but I try to help you with my own poor english !

I don't know how you read your datasource.
Is it by a XML file ?
Or by a database like Access ?
Or else ?

If it's by a database, I suppose you have a connection on it.
Then, you only need a SQL request to fill your combobox.

But, if you load a XML file with dataset.fromxml, it's seems you can't use
SQL request.

In this case, I have a fucntion witch look like a simple SQL request but my
function works with only one table and only one condition.

You just have to call the function directly in the datasource property of
your combobox with 2 args : the table, and the condition (like "Id_User=" &
val.ToString)

MaComboBox.DataSource = requete_1_table_et_1_critère(DataSource, critère)



Function requete_1_table_et_1_critère(ByVal DataSource As DataTable, ByVal
critère As String) As DataTable

Dim index_égal As Integer = critère.IndexOf("=")

If index_égal > 0 AndAlso index_égal < critère.Length - 1 Then

Dim tmp_ds As New DataSet

Dim tmp_dt As DataTable = tmp_ds.Tables.Add("tmp")

Dim tmp_r As DataRow

Dim tmp_c As DataColumn

Dim columnName As String

Dim columnValue As String

columnName = critère.Substring(0, index_égal)

columnValue = critère.Substring(index_égal + 1, critère.Length -
index_égal - 1)

For columnIndex As Integer = 0 To DataSource.Columns.Count - 1

tmp_c = New DataColumn(DataSource.Columns(columnIndex).ColumnName)

tmp_dt.Columns.Add(tmp_c)

Next

For Each dr As DataRow In DataSource.Rows

If dr.Item(columnName) = columnValue Then

tmp_r = tmp_dt.NewRow

For columnIndex As Integer = 0 To DataSource.Columns.Count - 1

tmp_r.Item(columnIndex) = dr.Item(columnIndex)

Next

tmp_dt.Rows.Add(tmp_r)

End If

Next

Return tmp_dt

Else

Return Nothing

End If

End Function


Have a good day,

Stéphane



"sfauchille" a écrit dans le message de news:

Hello,

My Problem.


I have 2 classes
ClsEnterprise
ClsUser


The ClsEnterprise has property :
Id_Ent
Name
....


The ClsUser has property :
Id_User
Name
Id_Ent
....


and 2 others Classes
ClsEnterprises as list (of ClsEnterprise)
ClsUsers as list (of ClsUser)


I have 2 combo box
CboUser
CboEnterprise


To fill the combo
CboUser.DataSource = ClsUsers
CboUser.DisplayMenber ="Name"
CboUser.ValueMember = "IdUser


CboEnterprise.DataSource = ClsEnterprises
CboEnterprise.DisplayMenber ="Name"
CboEnterprise.ValueMember = "IdEnterprise


When I select an enterprise in the CboEnterprise I would like only to
show Users from this enterprise
How can i do???


I tried this but it doesn't work:
Dim Result = From Usr In Users() Where Usr.Id > CboReseaux.ValueMember
CboUser.DataSource = Result


Avatar
sfauchille
On 23 oct, 20:14, <Stéphane> wrote:
Hi englishman,

Here, it's in French, but I try to help you with my own poor english !

I don't know how you read your datasource.
Is it by a XML file ?
Or by a database like Access ?
Or else ?

If it's by a database, I suppose you have a connection on it.
Then, you only need a SQL request to fill your combobox.

But, if you load a XML file with dataset.fromxml, it's seems you can't us e
SQL request.

In this case, I have a fucntion witch look like a simple SQL request but my
function works with only one table and only one condition.

You just have to call the function directly in the datasource property of
your combobox with 2 args : the table, and the condition (like "Id_User =" &
val.ToString)

MaComboBox.DataSource = requete_1_table_et_1_critère(DataSource, crit ère)

Function requete_1_table_et_1_critère(ByVal DataSource As DataTable, By Val
critère As String) As DataTable

Dim index_égal As Integer = critère.IndexOf("=")

If index_égal > 0 AndAlso index_égal < critère.Length - 1 Then

Dim tmp_ds As New DataSet

Dim tmp_dt As DataTable = tmp_ds.Tables.Add("tmp")

Dim tmp_r As DataRow

Dim tmp_c As DataColumn

Dim columnName As String

Dim columnValue As String

columnName = critère.Substring(0, index_égal)

columnValue = critère.Substring(index_égal + 1, critère.Length -
index_égal - 1)

For columnIndex As Integer = 0 To DataSource.Columns.Count - 1

tmp_c = New DataColumn(DataSource.Columns(columnIndex).ColumnName)

tmp_dt.Columns.Add(tmp_c)

Next

For Each dr As DataRow In DataSource.Rows

If dr.Item(columnName) = columnValue Then

tmp_r = tmp_dt.NewRow

For columnIndex As Integer = 0 To DataSource.Columns.Count - 1

tmp_r.Item(columnIndex) = dr.Item(columnIndex)

Next

tmp_dt.Rows.Add(tmp_r)

End If

Next

Return tmp_dt

Else

Return Nothing

End If

End Function

Have a good day,

Stéphane

"sfauchille" a écrit dans le message de news:




> Hello,

> My Problem.

> I have 2 classes
> ClsEnterprise
> ClsUser

> The ClsEnterprise has property :
> Id_Ent
> Name
> ....

> The ClsUser has property :
> Id_User
> Name
> Id_Ent
> ....

> and 2 others Classes
> ClsEnterprises as list (of ClsEnterprise)
> ClsUsers as list (of ClsUser)

> I have 2 combo box
> CboUser
> CboEnterprise

> To fill the combo
> CboUser.DataSource  = ClsUsers
> CboUser.DisplayMenber  ="Name"
> CboUser.ValueMember  = "IdUser

> CboEnterprise.DataSource  = ClsEnterprises
> CboEnterprise.DisplayMenber  ="Name"
> CboEnterprise.ValueMember  = "IdEnterprise

> When I select an enterprise in the CboEnterprise I would like only to
> show Users from this enterprise
> How can i do???

> I tried this but it doesn't work:
>        Dim Result = From Usr In Users() Where Usr.Id =
> CboReseaux.ValueMember
>        CboUser.DataSource = Result- Masquer le texte des mess ages précédents -

- Afficher le texte des messages précédents -



Merci je vais essayer ça.
J'aurai pu te dire que j'étais français aussi!!!
Avatar
De rien !

Sinon, accessoirement, dans un groupe de discussion français, tu peux aussi
rédiger tes messages en...
français...

Stéphane.



"sfauchille" a écrit dans le message de news:



Merci je vais essayer ça.
J'aurai pu te dire que j'étais français aussi!!!