Combo values based on another combo value


Author
Message
Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 7K
Better yet, if you could post a sample versus my brain having to do the compiling and execution that would be great Smile
Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 7K
Good stuff Smile  Good answers, Edhy!
Edhy Rijo
E
StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
You're welcome Juan.

Edhy Rijo

Juan Carlos Pazos
Juan Carlos Pazos
StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)
Group: Forum Members
Posts: 144, Visits: 227
Hi

All solved. Thanks a lot for your help.

Smile Everything is possible, just keep trying...

Juan Carlos Pazos
Juan Carlos Pazos
StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)
Group: Forum Members
Posts: 144, Visits: 227
Hi Edjy

Thanks for all your support. I still trying. If your have some simple sample, will be very good?

I think that in the ListPopulating should go the:

If Me.DetalleSubcategoriasBO.Count > 0 Then

e.Parameters(0).Value = Me.DetalleSubcategoriasBO.IdStio

Else

e.Parameters(0).Value = 0

End If

And in the SelectedIndexChanged the Requery()

Regards.



Smile Everything is possible, just keep trying...
Edhy Rijo
E
StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Juan Carlos,

All you need to understand here is how the relation between the 3 tables works, then in the Combobox.SelectedIndexChanged you have to check the ParentBO.Count > 0, so if there is a record, then you can sent the ParentBO.PKFieldValue to the first parameter e.Parameters(0).Value = Me.ParentBO.PKFieldValue.

In the Categories Combobox SelectedIndexChanged use this code:

If Me.CategoriasPubBO.Count > 0 Then

     e.Parameters(0).Value = Me.CategoriasPubBO.YourPKFieldNameHere

Else

     e.Parameters(0).Value = 0

End If

Also I believe it is better to use sample with your real entities name, even if it is in Spanish, this way it will make more sense when posting real code Smile.

Edhy Rijo

Juan Carlos Pazos
Juan Carlos Pazos
StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)
Group: Forum Members
Posts: 144, Visits: 227
Hi

This is what I have:

I uses a Contry - States - Cites sample, my tables are Sitios (sites), Categorias (categories) and Subcategorías (subcategories), is the same.

When the user add a new record or edit one existing, firs select the site, the category and the subcategory, then two more fields that are just text.

I already made a for for add sites, then another for add categories, in that I used the code you kindly provide me, and works fine.

In this form is for subcategories, I repeat all code just adjusting the for the last combo.

In the Sites combo the PopulatingDataSourceSettings is: CategoriasPubBO.FillBySitio(System.Int32) FillBySitio is a query to the BO that retrieves all the values in the table. The PopuleteOnFormLoad is on FormLoad

In the event SelectedIndexChanged has this: Me.cboCategoria.Requery()

The Cataegories Combo PopulatingDataSourceSettings is: CategoriasPubBO.FillBySitio(System.Int32) where the query in the BO is:

Public Sub FillBySitio(ByVal Sitio As Integer)

'-- Locals

Dim loCommand As New SqlCommand()

'-- Build the query

loCommand.CommandText = "SELECT * FROM Categorias_Pub WHERE IdSitio = @IdSitio"

'-- Add parameter

loCommand.Parameters.Add("@IdSitio", SqlDbType.Int)

loCommand.Parameters("@IdSitio").Value = Sitio

'-- Execute command

Me.FillDataTable(loCommand)

End Sub

In the SelectedIndexChanged has this:

If Me.DetalleSubcategoriasBO.Count > 0 Then

e.Parameters(0).Value = Me.DetalleSubcategoriasBO.IdStio

Else

e.Parameters(0).Value = 0

End If

The DetalleSubcategoriasBO is the bussines object for the form.

In the SelectedIndexChanged has this: Me.cboSubcategoria.Requery()

The PopulationDataSourceSettings are: SubCategoriasBO.FillByCategoria(System.Int32) and the PopulateOnFormLoad is in manual (I all rady put this in OnLoad and not works).

Public Sub FillByCategoria(ByVal Sitio As Integer)

'-- Locals

Dim loCommand As New SqlCommand()

'-- Build the query

loCommand.CommandText = "SELECT * FROM SubCategorias_Pub WHERE IdCategoria = @IdCategoria"

'-- Add parameter

loCommand.Parameters.Add("@IdCategoria", SqlDbType.Int)

loCommand.Parameters("@IdCategoria").Value = Subcategoria

'-- Execute command

Me.FillDataTable(loCommand)

End Sub

The ListPopulation event is this:

If Me.DetalleSubcategoriasBO.Count > 0 Then

e.Parameters(0).Value = Me.DetalleSubcategoriasBO.IdStio

Else

e.Parameters(0).Value = 0

End If

Finally the ListPopulating event in the las combo is this:

If Me.DetalleSubcategoriasBO.Count > 0 Then

e.Parameters(0).Value = Me.DetalleSubcategoriasBO.IdCategoria

Else

e.Parameters(0).Value = 0

End If

Hope it makes sense and you can help me.

Regards



Smile Everything is possible, just keep trying...
Edhy Rijo
E
StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi Juan,

Please post the code of the populating event and the one that is causing the error.  It is a bit difficult to help you debug without looking at your code.  I am sure it is something very simple.  Also FYI, what you are trying to do with all your combos, can also be done in the Dialog Browser, in case you needed to know. Wink

Edhy Rijo

Juan Carlos Pazos
Juan Carlos Pazos
StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)
Group: Forum Members
Posts: 144, Visits: 227
Hi

I have records in the three tables. In fact the problem, is generated in the Requery(), the event for the list with the validation for 0 is passed correctly.

Any ideas?

Smile Everything is possible, just keep trying...

Edhy Rijo
E
StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Juan Carlos, it is the same rule for all combos you want to use.  The CurrentRowIndex: -1 error is due to the fact that the States_Pub BO does not have any records, so you need to check for this combo.count > 0 before trying to use it.  Look at the sample code I posted here before.

Edhy Rijo

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search