Selectitem in combobox

Posts   
 
    
jspruit
User
Posts: 17
Joined: 11-Nov-2005
# Posted on: 19-Jul-2007 11:39:06   

Hi,

I use the following code to select an item in a combobox with LLBLGen Pro version: 2.0.0.0:


DataAccessAdapter adapter = new DataAccessAdapter();

                ComponentcatalogEntity compent = new ComponentcatalogEntity(itemid);
                adapter.FetchEntity(compent);
                curid = compent.Compnr ;
                txSerie.Text = compent.Serienr;
                txType.Text = compent.Type;

                
                compent.Modelcatalog = (ModelcatalogEntity)adapter.FetchNewEntity(new ModelcatalogEntityFactory(), compent.GetRelationInfoModelcatalog());

                cmbModel.SelectedItem = compent.Modelcatalog;

What happens is that the first time the combobox isn't set to selected item, but when function is called a second time combobox will select correct item.

any ideas ?

Thanks in advance,

Jan

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 19-Jul-2007 15:40:35   

Did you try setting the SelectedValue instead? Also what's the .NET Framework version and LLBLGen Pro runtime library version?

jspruit
User
Posts: 17
Joined: 11-Nov-2005
# Posted on: 19-Jul-2007 16:16:46   

Walaa wrote:

Did you try setting the SelectedValue instead? Also what's the .NET Framework version and LLBLGen Pro runtime library version?

Hi,

i tried SelectedValue too but still same problem first time not working, second, third... time it works fine.

.Net version: 2.0.07.0416

LLBL Runtime library version for MS Access:2.0.07.0416

Thanks,

Jan

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 20-Jul-2007 11:57:44   

Is this routine called from the form's CTor or from the form's load event handler or somewhere else? (I think it's a winforms related issue)

Frans Bouma | Lead developer LLBLGen Pro
jspruit
User
Posts: 17
Joined: 11-Nov-2005
# Posted on: 20-Jul-2007 12:08:26   

Otis wrote:

Is this routine called from the form's CTor or from the form's load event handler or somewhere else? (I think it's a winforms related issue)

Hi,

I call a function to update details when an item has been selected in my datagrid (_CellClick). When i debug it i see it gets the correct primary key and al other data is updated correctly in details (other combo and several textboxes). Only one combo isn't updated. Next time i select this or another item in my datagrid combo is updated correctly. It only happens first time i select an item.

Thanks,

Jan

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 20-Jul-2007 16:25:48   

Is this a .NET 1.x (V.S. 2003) ? Or a .NET 2.0 (V.S. 2005)?

jspruit
User
Posts: 17
Joined: 11-Nov-2005
# Posted on: 20-Jul-2007 16:30:20   

Walaa wrote:

Is this a .NET 1.x (V.S. 2003) ? Or a .NET 2.0 (V.S. 2005)?

Hi,

.Net version: 2.0.07.0416 (VS 2005)

Regards,

Jan

Posts: 254
Joined: 16-Nov-2006
# Posted on: 22-Jul-2007 00:17:41   

What happens is that the first time the combobox isn't set to selected item, but when function is called a second time combobox will select correct item.

If you put a break point on the call to set selecteditem is the object being passed a valid object reference, or is this null?

jspruit
User
Posts: 17
Joined: 11-Nov-2005
# Posted on: 23-Jul-2007 09:44:15   

Hi,

I changed the code to

cmbModel.SelectedValue = compent.Modnr;

This still gives the same problem. When i debug it i see that compent.Modnr has the correct value, somehow this isn't passed to the combobox first time.

I now made a workaround just calling the function twice and this works fine.disappointed

Not the most elegant way ofcourse....

Jan

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 23-Jul-2007 09:48:09   

Also you may try to call comboBox.DataBind();

jspruit
User
Posts: 17
Joined: 11-Nov-2005
# Posted on: 23-Jul-2007 10:18:19   

Walaa wrote:

Also you may try to call comboBox.DataBind();

Hi,

I do not have a comboBox.DataBind() method ??

Jan

jbb avatar
jbb
User
Posts: 267
Joined: 29-Nov-2005
# Posted on: 23-Jul-2007 16:37:11   

Hello,

Did you combobox is initialized later in the form? Could you create a function bind OnSelectedIndexChange event and see in the call stack, when is it called?

jspruit
User
Posts: 17
Joined: 11-Nov-2005
# Posted on: 23-Jul-2007 17:01:24   

jbb wrote:

Hello,

Did you combobox is initialized later in the form? Could you create a function bind OnSelectedIndexChange event and see in the call stack, when is it called?

Hi,

I fill the combobox from filtered collection in the formload event. But it also changes when another combobox on the form changes as this makes the filter of collection on the second combo.

First time selection of item, OnSelectedIndexChange is fired twice:

OnderhoudPBS.exe!OnderhoudPBS.ComponentCatalogus.cmbModel_SelectedIndexChanged(object sender = {System.Windows.Forms.ComboBox, Items.Count: 1}, System.EventArgs e = {System.EventArgs}) Line 403   C#
>   OnderhoudPBS.exe!OnderhoudPBS.ComponentCatalogus.cmbModel_SelectedIndexChanged(object sender = {System.Windows.Forms.ComboBox, Items.Count: 19}, System.EventArgs e = {System.EventArgs}) Line 403  C#

Second time it is fired only once:


>   OnderhoudPBS.exe!OnderhoudPBS.ComponentCatalogus.cmbModel_SelectedIndexChanged(object sender = {System.Windows.Forms.ComboBox, Items.Count: 19}, System.EventArgs e = {System.EventArgs}) Line 403  C#

It looks like for some reason first time collection in combo is empty when new filter has been applied

Thanks,

Jan

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 24-Jul-2007 11:48:29   

I still don't know why this happens and it's very confusing what's going on exactly. Please produce a simple repro example to show what happens. Thanks.

Frans Bouma | Lead developer LLBLGen Pro
jspruit
User
Posts: 17
Joined: 11-Nov-2005
# Posted on: 16-Aug-2007 12:12:23   

Hi,

After being of the project for a couple of weeks i finally discovered what was going on.

Ok I admit : IT WAS MY MISTAKE.

cmbModel combobox itemlist changes when cmbfabr selection changes.

What happened is that i first tried to set cmbModel to a certain item and then cmbFabr which is the wrong way ofcourse, that way it could be that item is not present in cmbModel.

stuck_out_tongue_winking_eye

Anyway thanks for all your effort helping to solve this problem

Jan

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 16-Aug-2007 15:12:42   

Thanks for the feedback.