Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mutually exclusive data grids

Status
Not open for further replies.

need2progm

Programmer
Dec 13, 2002
92
US
I have an ASP.net page with 2 data grids.... each with a collection ie:Names... when one name is chosen on Grid A it goes to Grid B. These grids need to be mutually exclusive. How can I do that with out putting my hands on every item in each collection.
 
If you're doing what I think you're doing, I wouldn't use datagrids at all; we do this functionality in our project with listboxes and a button.

(This assumes that you only need to show one item of data per table though, not multiple. i.e. name instead of name, address, branch, etc.)

Maybe explain a bit more of what this is supposed to do, and we can go from there

D'Arcy
 
I am attempting to bind a grid to a collection of "A" objects.
Each of these objects has a property that is a collection of other "B" objects.
I would like the gridA to show me the A.Name properties as the 'root' of the 'hierarchical' grid and the collection of A.B.Name as the 'nodes' of the grid.
I need to add several other A.B.properties to the grid eventually, and do some editing. Seems to be easier in a grid then tree or list. Thanks in advance.
 
Ah, ok, now I understand.

Now, you mentioned not wanting to put your hands on each item in every collection, and I'm not really sure what you mean by that. So I'll explain how I'd go about doing what you're trying, and if you have any other questions or I'm way off base just let me know.

So, you're first datagrid (A) should be easy to do:
Just grab all your A objects and fill the grid. Just make sure that you have a button column ('Select') in the grid.

When the user clicks on the select, grab a unique identifier for that record
(e.cells(indexofcellwithidentifier).Text)
and pass it to some sub that will get all the B objects related to the selected A's ID. Once you have that list, just fill the second grid.

hth

D'Arcy
 
Yes... you are on the right track... :) I am able to get the related object of selected Grid A item and fill 2nd Grid .. where I am getting hung up is having to 'delete' from Grid A's collection what is now in Grid B's 'new' collection. With out having to for_each and loop through every item in collection Grid A and if in Grid B collection then delete. It doesn't seem right to touch every item when 25 out of 100 are selected.
 
heh..ok, sorry, I got lost again. Tell me if this is whats going down:

Grid A Names
------------
NameID Name
1 Name1
2 Name2
3 Name3

I select Name2, which gets information from another table that is related to Name2

Grid B Info
-----------
InfoID Desc NameID
1 Info1 2
2 Info2 2
3 Info3 2

So now, if I delete an item from Grid B I have two options:
1. Delete the item from the database, then rebind the grid (which will just get all the Info records associated with NameID 2. Since we deleted the Info record already, it won't show up in the grid)
2. Store all the InfoId's that are flagged to be deleted, then do a bulk delete

If a Name is deleted from Grid A, then either have code that will go through and delete all teh records associated with that name, or have the database take care of that with a cascade delete.

K, let me know if this covers what you're looking for, or if I'm still off the mark
;)

hth

D'Arcy
 
Almost...
Grid A Names Grid B Names
Collection New Collection
------------ ------------
NameID Name NameID Name
1 Name1 < 1 Name1
2 Name2 > 2 Name2
3 Name3
4 Name4
5 Name5

Bulk delete sounds good
?
'Go backwards in collection to remove unwanted names from Grid A
Dim count As Int32
For count = (Grid.Rows.Count - 1) To 0 Step -1
If Grid.Rows(count).GetCellValue(Grid.Columns.FromKey(&quot;MOVE&quot;)) = True Then
Grid.Rows(count).Delete()
End If
Next
Thoughts?
Got to be a better way
 
Ah, ok, so you are doing what I thought you were.

yeah, there is a better way: Listboxes, two buttons to add items from one list to another, and no datagrids.

When a button is pressed to add an item from A to B, then all you do is get the selected item in A, add it to B, and remove it from A (the code for this is literally a few lines).

Once its time to commit the changes in the database, you just need to delete each item from whichever list you don't want.

We've done this in our project, and it works really well!

If you need a pointer for writing the code, just let me know

D
 
I am interested in a pointer for the code. I did something similar, but mine took alot more than a few lines. I am interested in a different approach for it, especially since it sounds like there is a much easier way to do it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top