using a datgridView to SELECT the entity, but NOT to edit the entity

Posts   
 
    
yogiberr
User
Posts: 432
Joined: 29-Jun-2005
# Posted on: 30-Jan-2006 12:42:03   

version 1.0.2005.1 final (self-servicing) VS2005 winforms


hiya,

I want to select a row in a datagridView and then display the details of that particular row in a section that contains textBoxes and comboboxes.(readWrite) In other words, I do not want to do the editing in the datagrid.

I am not sure whther I should bind the datagridView to :

1) an entityCollection, and then using a bindingContext to use the SAME datasource to display the details in the textBoxes and combos etc.

2) a typedList, then send the primaryKey of the selected typedList item as an arg to an entity, then assign the values of the returned entity to the respective textBoxes and combos etc...

A vague question I know, but I can clarify anything that is ambiguous.

many thanks,

                  yogi
mihies avatar
mihies
User
Posts: 800
Joined: 29-Jan-2006
# Posted on: 30-Jan-2006 14:42:54   

yogiberr wrote:


version 1.0.2005.1 final (self-servicing) VS2005 winforms


hiya,

I want to select a row in a datagridView and then display the details of that particular row in a section that contains textBoxes and comboboxes.(readWrite) In other words, I do not want to do the editing in the datagrid.

I am not sure whther I should bind the datagridView to :

1) an entityCollection, and then using a bindingContext to use the SAME datasource to display the details in the textBoxes and combos etc.

2) a typedList, then send the primaryKey of the selected typedList item as an arg to an entity, then assign the values of the returned entity to the respective textBoxes and combos etc...

A vague question I know, but I can clarify anything that is ambiguous.

many thanks,

                  yogi

I don't use DataGridView though according to documentation it has ReadOnly property you might set to true.

JimHugh
User
Posts: 191
Joined: 16-Nov-2005
# Posted on: 30-Jan-2006 14:44:19   

One advantage of using an EntityCollection bound to the DataGridView and the Textboxes at the same time is that changes to the data done in the TextBoxes will show up the in the DataGridView wihtout needing to requery.

Since you are on 2005, I would recommend using a BindingSource to bind to the form controls and then set the BindingSource.Datasource of the to the entity collection.

mihies avatar
mihies
User
Posts: 800
Joined: 29-Jan-2006
# Posted on: 30-Jan-2006 15:45:14   

JimHugh wrote:

One advantage of using an EntityCollection bound to the DataGridView and the Textboxes at the same time is that changes to the data done in the TextBoxes will show up the in the DataGridView wihtout needing to requery.

Since you are on 2005, I would recommend using a BindingSource to bind to the form controls and then set the BindingSource.Datasource of the to the entity collection.

Yup, BindingSource is the way to go.

yogiberr
User
Posts: 432
Joined: 29-Jun-2005
# Posted on: 30-Jan-2006 21:14:06   

hiya,

ta for the replies. Ok, I'm new to the bindingSource gig.I can bind the:

1) datagridView to the entityCollections 2) textBox to the bindingSource

However, the textBox only seems to pick up the FIRST item in the bindingSource.I want the textBox.text to change, so that it reflects the currently selected row of the datagridView.

here's my code so far, can anyone help?



            TblProductCollection currProducts = new TblProductCollection();
            currProducts.GetMulti(null);

            productsBindingSource.DataSource = currProducts;  

             dgvProducts.DataSource = currProducts;  //bind entityCollection to datagridview

             txtPrice.DataBindings.Add("text", productsBindingSource, "price");

I might of course be doing this entirely wrong flushed

many thanks, yogi

JimHugh
User
Posts: 191
Joined: 16-Nov-2005
# Posted on: 30-Jan-2006 22:32:33   

Close, change


            dgvProducts.DataSource = currProducts; 

to


            dgvProducts.DataSource = productsBindingSource; 

Think of it as a chain with two links that you can control. That way if you replace the entity collection, you won't have to rebind all of the the controls, just the one BindingSource.DataSource. The BindingSource acts as a broker.

entitycollection -> BindingSource -> boundcontrols

Changing the Position of the BindingSource will change the selected row in the grid and vice versa. The textbox will also follow the BindingSource position.

yogiberr
User
Posts: 432
Joined: 29-Jun-2005
# Posted on: 30-Jan-2006 23:53:52   

cheers Jim,

I did that but it didn't make any difference.I think that maybe you think that I posted a short sample of code for brevity.I didn't, that was the entire code..Here is what I now have below:



            TblProductCollection currProducts = new TblProductCollection();
            currProducts.GetMulti(null);

            productsBindingSource.DataSource = currProducts; 

             dgvProducts.DataSource = productsBindingSource; 
             txtPrice.DataBindings.Add("text", productsBindingSource, "price");


hmm, I think I must have to assign the current selection in a datagridView event? There's definitely something I am missing.If I could see a similar sample then I'm sure I could piece it together :-)

many thanks,

yogi

mihies avatar
mihies
User
Posts: 800
Joined: 29-Jan-2006
# Posted on: 31-Jan-2006 00:28:26   

BindingSource should do the trick (every consumer using it as datasource should position on the same record). However, I just read this text in help file (databidning topic): 'You should use the BindingSource used on your form to only setup the grid, and you should select an entity class, not a collection class. This because in adapter for example the designer for setting up the collection is no longer called by VS.NET 2005. Once you've setup the grid, you then should bind the real entity collection at runtime.' Perhaps this is something that has changed (i am using demo version). BTW, I am having problems even doing simple binding. I guess I am not an expert in LLBLGen simple_smile

JimHugh
User
Posts: 191
Joined: 16-Nov-2005
# Posted on: 31-Jan-2006 08:12:10   

I'm not sure what is not working at this point.

I'm assuming that when you set BindingSource to the Grid Datasource you don't see any columns... It that right?

Based on what I have seen so far, you have to have column definitions in place, they don't seem to get auto generated when you use a bindingsource.

There are at least two ways to get them defined.

  1. Manually add each column, being sure to set the "DataPropertyName" for each corresponding property.

  2. Using the IDE, add a EntityCollection from the toolbox setting the factory, set the BindingSource.Datasource property and set the DatagridView.Datasource property. As soon as you do that, all of the columns will show up in the DataGridView designer and you can tweak as necessary.

yogiberr
User
Posts: 432
Joined: 29-Jun-2005
# Posted on: 31-Jan-2006 10:28:25   

hiya Jim,

I'm assuming that when you set BindingSource to the Grid Datasource you don't see any columns... It that right?

No, I can see all the columns, they are there.Unfortunately I am out of the office at the moment, and across the atlantic from you. When I get to my code, would it be of any value to post the designer partial class code that contains the datagridView settings?

That is, AFTER I have tried to use your steps with a new datagridView..that way, I can be sure that there are non "non-default" settings in the gridView.

many thanks, yogi

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 31-Jan-2006 10:47:13   

mihies wrote:

BindingSource should do the trick (every consumer using it as datasource should position on the same record). However, I just read this text in help file (databidning topic): 'You should use the BindingSource used on your form to only setup the grid, and you should select an entity class, not a collection class. This because in adapter for example the designer for setting up the collection is no longer called by VS.NET 2005. Once you've setup the grid, you then should bind the real entity collection at runtime.' Perhaps this is something that has changed (i am using demo version). simple_smile

That's for the design time databinding part. If you select 'bindingsource' in the dialog to add a new datasource and you then select 'entitycollection' the one selected doesn't have a factory nor will it get one. (the designer isnt called).

Btw, your post showed I made a mistake somewhere in my UBB parser for this forum this weekend. The string wasn't showing up, sorry for that.

(edit): fixed that simple_smile

Frans Bouma | Lead developer LLBLGen Pro
mihies avatar
mihies
User
Posts: 800
Joined: 29-Jan-2006
# Posted on: 31-Jan-2006 15:41:27   

Otis wrote:

That's for the design time databinding part. If you select 'bindingsource' in the dialog to add a new datasource and you then select 'entitycollection' the one selected doesn't have a factory nor will it get one. (the designer isnt called).

Ah, I see. Perhaps the docs are a little ambiguous here: 'Once you've setup the grid, you then should bind the real entity collection at runtime.' It seemed to me like I shuld ignore the bindingsource and bind collection directly to grid. (perhaps it is just my english)

Otis wrote:

Btw, your post showed I made a mistake somewhere in my UBB parser for this forum this weekend. The string wasn't showing up, sorry for that.

(edit): fixed that simple_smile

You can't never ever foresee the stupid things a programer will write wink

mihies avatar
mihies
User
Posts: 800
Joined: 29-Jan-2006
# Posted on: 31-Jan-2006 15:45:17   

yogiberr wrote:

hiya Jim,

No, I can see all the columns, they are there.Unfortunately I am out of the office at the moment, and across the atlantic from you. When I get to my code, would it be of any value to post the designer partial class code that contains the datagridView settings?

That is, AFTER I have tried to use your steps with a new datagridView..that way, I can be sure that there are non "non-default" settings in the gridView.

I just tried you scenario: I created a bindingsource and bound it to both datagridview and text box. I defined the source entity as object source. Then at runtime I just populate an EnitityCollection and use it as source to bindingsource.

No problems whatsoever. The textbox displays the data from same entity instance as it is selected in grid.

yogiberr
User
Posts: 432
Joined: 29-Jun-2005
# Posted on: 31-Jan-2006 22:26:16   

okay folks,

Can we keep this REALLY simple? A posted example would be great, but failing that, this is what I am confused about:

I created a bindingsource and bound it to both datagridview and text box. I defined the source entity as object source. Then at runtime I just populate an EnitityCollection and use it as source to bindingsource.

1) did you use the toolbox to add a bindingSource to the winform at design-time? 2) did you bind the bindingSource to both the datagridView and textBox, BEFORE you assigned anything to the bindingSource? 3) how did you databind to the textBox, did you use its databindings collection? 4) are you saying that you assign a SINGLE "entity" to the bindingSource? 5) if so why would you overwrite the bindingSource by assigning an entityCollection to it?

Sorry for all the questions, but a simple code example might give me all the clues that I need (c# / vb.net)

Many thanks,

yogi

mihies avatar
mihies
User
Posts: 800
Joined: 29-Jan-2006
# Posted on: 31-Jan-2006 23:45:35   

1) did you use the toolbox to add a bindingSource to the winform at design-time?

Yep.

2) did you bind the bindingSource to both the datagridView and textBox, BEFORE you assigned anything to the bindingSource?

No. I assigned entity before (otherwise you can't bind textbox because you don't have fields).

3) how did you databind to the textBox, did you use its databindings collection?

Yes.

4) are you saying that you assign a SINGLE "entity" to the bindingSource?

At design time - so the binding source knows the fields.

5) if so why would you overwrite the bindingSource by assigning an entityCollection to it?

That was my misunderstanding of docs. Assigning EntityCollection to bindingsource is just fine.

Sorry for all the questions, but a simple code example might give me all the clues that I need (c# / vb.net)

Code is really simple: EntityCollection coll = new EntityCollection(new SecurityGroupEntityFactory()); adapter.FetchEntityCollection(coll, null); bindingSource1.DataSource = coll;

Where bindingSource1 is the BindingSource for both grid and text box. Does it help?

yogiberr
User
Posts: 432
Joined: 29-Jun-2005
# Posted on: 01-Feb-2006 02:12:43   

hiya Miha,

Ta for replying. I am using the self-servicing adapter, I hope that is not my problem.

4) are you saying that you assign a SINGLE "entity" to the bindingSource?

At design time - so the binding source knows the fields.

Ok, so I assume that you use the properties window of the bindingSource? I selected an "object" then selected the following value for its dataSource:

myProject.EntityClasses.TblProductEntity

Where bindingSource1 is the BindingSource for both grid and text box.

you say that "bindingSource1 is the BINDINGSOURCE for both grid and text box." However, I don't think that the grid or textbox expose a a "BindingSource" property.

I can only see a datasource / bindingContext property:


TblProductCollection currProducts = new TblProductCollection();
            currProducts.GetMulti(null);
            
            productsBindingSource.DataSource = currProducts;
            dgvProducts.DataSource = productsBindingSource;

            txtPrice.DataBindings.Add("text", productsBindingSource, "price");      


many thanks for any suggestions..

yogi

mihies avatar
mihies
User
Posts: 800
Joined: 29-Jan-2006
# Posted on: 01-Feb-2006 10:16:41   

yogiberr wrote:

hiya Miha,

Ta for replying. I am using the self-servicing adapter, I hope that is not my problem.

I don't think so. It shouldn't matter.

yogiberr wrote:

you say that "bindingSource1 is the BINDINGSOURCE for both grid and text box." However, I don't think that the grid or textbox expose a a "BindingSource" property.

I can only see a datasource / bindingContext property:

I did mean that you use the same BindingSource instance for both.

yogiberr wrote:

many thanks for any suggestions..

If you want to you might send me your sources and I'll take a look (let the sample be as simple as possible). my email is: miha nospam@ rthand nospam com

yogiberr
User
Posts: 432
Joined: 29-Jun-2005
# Posted on: 01-Feb-2006 15:10:15   

many thanks Miha,

I will do do so when I return home this evening (I am out on site).

One thing though, I using the VS2005 RAD databinding in the same project. ie, binding some other datagridViews to bindingSources via RAD datasets.

I don't think that this would affect my datgridView, but I thought I'd mention it, just in case.

cheers,

yogi

yogiberr
User
Posts: 432
Joined: 29-Jun-2005
# Posted on: 01-Feb-2006 20:30:24   

okay, I had made a total arse of it.

The datagridView was ALREADY bound to the VS2005 RAD dataset flushed

It seems to work now. Thanks Jim, Miha and Otis.

There's no accounting for stupidity sunglasses

yogi

mihies avatar
mihies
User
Posts: 800
Joined: 29-Jan-2006
# Posted on: 01-Feb-2006 22:16:31   

Everybody has such days :-) Glad that it works now.