datagridView and combobox + bindingSource

Posts   
 
    
yogiberr
User
Posts: 432
Joined: 29-Jun-2005
# Posted on: 30-Apr-2006 16:37:51   

version 1.0.2005.1 final (self-servicing) VS2005 winforms


hiya,

I have a datagridview and a combobox which are on the same winform. the combobox is outside the datagridView.

The datagridview displays all the products that are associated with a particular delivery. The combobobox should display the correct van driver for the delivery.

my problem:

The datagridView dataSource does NOT contain the "driverId" field that I need. (this field is in another PARENT collection)

So, how can I set the correct van driver for the respective delivery?



   TblDriverCollection.GetMulti(null);
   cboDeliveryDrivers.DisplayMember = myProject.TblDriverFieldIndex.DriverName.ToString();
   cboDeliveryDrivers.ValueMember = myProject.TblDriverFieldIndex.DriverId.ToString();
   cboDeliveryDrivers.datasource = TblDriverCollection
    
tblDeliveryProdutsCollection1.GetMulti(null);
driverBindingSource.DataSource = tblDeliveryProdutsCollection1;
cboDeliveryDrivers.DataBindings.Add(new Binding("SelectedValue", this.driverBindingSource, TblDriverFieldIndex.DriverId.ToString(), true));
        }

<schemas>

tblDeliveryProducts deliveryId PK productId PK qty

tblDriver driverId PK driverName

tbldelivery deliveryId PK driverId ----THIS IS THE FIELD THAT I REQUIRE..BUT THIS FIELD IS NOT IN THE DATAGRIDVIEW.

</schemas>

I can clarify further and post more code, but i don't want to confuse the issue.

Can anyone help?

many thanks,

yogi

sparmar2000 avatar
Posts: 341
Joined: 30-Nov-2003
# Posted on: 30-Apr-2006 17:22:08   

can you show the code that populated the datagridview ?

yogiberr
User
Posts: 432
Joined: 29-Jun-2005
# Posted on: 30-Apr-2006 17:37:01   


TblDeliveryProductsCollection currDeliveries = new TblDeliveryProductsCollection();

currDeliveries.GetMulti(filter);
                    
            currDeliveries.SupportsSorting = true;

            tblDeliveryProductsCollectionBindingSource.DataSource = currDeliveries;
            dgvDeliveryProducts.DataSource = tblDeliveryProductsCollectionBindingSource;

JimHugh
User
Posts: 191
Joined: 16-Nov-2005
# Posted on: 30-Apr-2006 17:55:30   

The datagridview displays all the products that are associated with a particular delivery.

The top level bindingsource should therefore be a tblDelivery collection, which includes the driverid for the current delivery.

The datagridview should only show products associated with current delivery and therefore should be bound to a child collection of the delivery and not to all delivery products. (don't use tblDeliveryProdutsCollection1.GetMulti(null); here!)


TblDeliveryCollection currDeliveries = new TblDeliveryCollection();
// filter limits delivery to a single delivery, probably by PK
currDeliveries.GetMulti(filter);
this.BindingSourceTblDelivery.Datasource = currDeliveries;

// Specifying child collection of current delivery, limits datagridview to products
// associated with current delivery
// tblDeliveryProductsBindingSource is a second bindingsource added to form and used as Datasource for products datagridview
tblDeliveryProductsBindingSource.DataSource = currDeliveries,TblDeliveryProducts;

// gets all available drivers
TblDriverCollection.GetMulti(null);
cboDeliveryDrivers.DisplayMember = myProject.TblDriverFieldIndex.DriverName.ToString();
cboDeliveryDrivers.ValueMember = myProject.TblDriverFieldIndex.DriverId.ToString();
cboDeliveryDrivers.datasource = TblDriverCollection

// binds Delivery driverid to current delivery
cboDeliveryDrivers.DataBindings.Add(new Binding("SelectedValue", this.BindingSourceTblDelivery, TblDriverFieldIndex.DriverId.ToString(), true));

some pseudo code shown here so adapt as required.

JimHugh
User
Posts: 191
Joined: 16-Nov-2005
# Posted on: 30-Apr-2006 18:52:32   

One minor change...


this.tblDeliveryProductsBindingSource.DataSource = currDeliveries,TblDeliveryProducts;

should read


this.tblDeliveryProductBindingSource.DataMember = "TblDeliveryProduct";
this.tblDeliveryProductBindingSource.DataSource = this.BindingSourceTblDelivery;

yogiberr
User
Posts: 432
Joined: 29-Jun-2005
# Posted on: 03-May-2006 23:24:42   

thanks Jim.

I have been getting a few databinding errors when trying to convert the datasource.

I'm getting confused (because it's my first llblgenpro project)..and there's loads of unused bindingSources and entityCollections on my winforms...

I think i'd be better off removing them before continuing.

Can anyone suggest the best way to find out WHICH design-time bindingSources etc

are surplus to requirements?

I know that it's not strictly related to my original post, but if I can get rid of the unused stuff then I can get this finished quicker.

many thanks,

yogi

JimHugh
User
Posts: 191
Joined: 16-Nov-2005
# Posted on: 04-May-2006 02:49:08   

Can anyone suggest the best way to find out WHICH design-time bindingSources etc are surplus to requirements?

You can open the form.designer.cs file and search for .DataSource, that will at least tell you what is in use.

You could also make backups of the form.cs, form.designer.cs and form.resx and remove stuff until it breaks simple_smile

yogiberr
User
Posts: 432
Joined: 29-Jun-2005
# Posted on: 08-May-2006 22:23:43   

hiya Jim.

Ta for all the help. It was much appreciated.

yogi