I'm using a c# usercontrol and what I'm trying to do is randomly select a group of nodes. Basically I've a 'question' node and under this node there is a number of questions (child nodes) and what I want to do is select say 20 of these questions at random and load them into a datatable.
I've got to the point where I can loop through all of the children and put them in a recordset but i'm don't know how to randomly select the nodes.
I know that I can randomise/sort the datatable itself but the problem that I have is that the datatable itself is being used for all sorts of nested relations and sorting on the table strips out the parent/child relations and naming conventions. Hence the question about randomly getting the node themselves and then I can build the table using these random nodes and keep the rest of my code intact.
ok, that's not easy. Sorry, but I have no concrete idea for this. Perhaps you can make a copy of your recordset to a new list and randomise this list. But I think the relations between the copied list and your recordset can be very tricky. And without code it is not easy to imagine this.
Randomly select nodes
Hi all,
I'm using a c# usercontrol and what I'm trying to do is randomly select a group of nodes. Basically I've a 'question' node and under this node there is a number of questions (child nodes) and what I want to do is select say 20 of these questions at random and load them into a datatable.
I've got to the point where I can loop through all of the children and put them in a recordset but i'm don't know how to randomly select the nodes.
Any help would be greatly appreciated.
Thanks,
Craig
Hi Craig,
you can do this with standard c# code. You can sort your list of childrens with the random function.
Here is an general example:
http://stackoverflow.com/questions/5383498/shuffle-rearrange-randomly-a-liststring
Hope this helps.
Best,
Sören
Thank Soren,
I know that I can randomise/sort the datatable itself but the problem that I have is that the datatable itself is being used for all sorts of nested relations and sorting on the table strips out the parent/child relations and naming conventions. Hence the question about randomly getting the node themselves and then I can build the table using these random nodes and keep the rest of my code intact.
Any ideas?
thanks,
Craig
Hi Craig,
ok, that's not easy. Sorry, but I have no concrete idea for this. Perhaps you can make a copy of your recordset to a new list and randomise this list. But I think the relations between the copied list and your recordset can be very tricky. And without code it is not easy to imagine this.
Cheers,
Sören
is working on a reply...