StrataFrame Forum

checked listbox question

http://forum.strataframe.net/Topic4855.aspx

By Paul Chase - 11/29/2006

I cannot seem to get this right but it has been a long weekSmile

I have 3 tables

Jobsite - contains info about a job

Equipment - contains a list of equipment (shovels,hard hats etc)

JsEquipment link table for first 2 tables contains a Pk and 2 FK's from each above tables JSE_PK,JBS_FK,EQP_FK

I want to use a checked listbox to allow the user to select which equipment needs to be used on the job. Can you give me a rundown on how to set up the checked listbox. I have tried but failed..BigGrin By the way all the primary and foreign keys are guid's

Thanks

P

By StrataFrame Team - 11/30/2006

You'll want to select all of the items from the JsEquipment table and populate the checked list box off of that.  When you build the list, you'll want to do one of 2 things:

1) do a left join of the JsEquipment on the link table so that you can tell what should be checked (if the field is NULL then it should be unchecked, otherwise, it should be checked)

2) you can add all of the nodes to a dictionary (System.Collections.Generic.Dictionary(Of Guid, TreeNode)) so you can access all of the tree nodes later by their primary key.  After you have the list populated, you will then need to be set the checked state on the nodes to their initial state... that's why you need the dictionary.  Do a join on the link table and cycle through the returned records calling TreeView.SetNodeState(Dictionary(LinkBO.EquipmentFK), True) to check them.

When you want to set the state of a node, you can use SetNodeState(node, true/false), which will set the checked state of the parent/child nodes as well.  Don't forget to store off the GuidPK of the piece of equipment in the tag of the node.

Once you have the list populated, you can use the NodeStateChanged event handler... do a .Seek() within the link table and either add or remove a record from the link table depending upon whether the node is checked or unchecked.

By Paul Chase - 11/30/2006

Thanks Ben that helps alot. I was driving on the wrong side of the road againSmile

P

By StrataFrame Team - 11/30/2006

It's OK to drive on the wrong side of the road sometimes... just as long as your steering wheel is still on the correct side and you don't have to shift with your left hand Smile
By Keith Chisarik - 3/28/2007

Any examples or sample code for checked listview control around?



I checked the documentation but all it seems to have is member/property definitions.



I checked the sample apps and could not find anything.



All I want to do is populate the listview from a single table/colum and allow the user to select some. I don't want it bound back to the table, so if I can just read the "checked" selections and be done that is the desire. Does it try to persist the values back to a field in your datasource? I can only imagine it does since it uses PopulationDataSourceSettings.....


By Keith Chisarik - 3/28/2007

I got it, its just like ListView pretty much with a CheckedItems collection.....


By Trent L. Taylor - 3/28/2007

This is just standard ListView behavior and we do not add any additional functionality here.  But to use a checked list view, just set the CheckBoxes property to True.  Then to set a ListView checked item it would just be setting the Checked property of the ListVIew item.

MyListView.Items(0).Checked = True

You can also referenced the CheckedItems collection to see which items have been checked rather than having to cycle through the Items collection and testing:

Dim loItem As ListViewItem

For Each loItem IN MyListView.CheckedItems
    '-- Place your code here to do something with the checked item
Next