Handling Click Events In MVVM Lite - mvvm-light

I have a GridView and handle the click event in the Code-Behind as follows:
void ItemView_ItemClick(object sender, ItemClickEventArgs e)
{
int itemId = ((Location)e.ClickedItem).Id;
Frame.Navigate(typeof(SectionPage), itemId))
}
The data is populated from the ViewModel. I would like to handle this click event in the ViewModel instead of the View, but I've not been able to figure out how to do that.
In addition, I am employing a drill down scenario, where each time an item is clicked in the GridView, it results in a similar grid with different data. The ICollection<Location> simply repeats itself three times, populating each new grid with similar data.
Currently I am using three different identical Views and ViewModels to accomplish this. It seems to me there must be a way to do this using the same View. In other words, click on an item and the view re-populates itself with a new set of data, based on the item clicked.
The data is supplied from a WebService. To obtain the new data, a separate method must be called for each View, passing in the itemId of the previous data. I cannot do this with one method as the keys are not unique across all methods.

Related

How to refresh list page and not loose focus in the grid?

I am opening detail of an item in list page grid. There may be some changes so after detail is close() I and refreshing the list page datasource.
I am acessing the list page datasource from arguments
FormDataSource callerDataSource;
callerDataSource = element.args().record().dataSource();
But I can obtain one of following results.
1) I reread() the current record.
callerDataSource.reread();
The data in grid are changed but the form parts do not refresh.
2) I research(true) the datasource
callerDataSource.research(true);
I try even this version of research
callerDataSource.reread();
callerDataSource.rereadReferenceDataSources();
callerDataSource.research(true);
but I lost focus in grid.
3) I call task F5 by
#Task
Element.args().caller().task(#taskF5);
but the focus is lost here too.
I would like to have new data in grid and in form part but do not lost focus in grid. (Refreshing of only selected record and info parts which depends on it will be enough.)
The table has primary index selected. It is recid (which is not shown in grid).
How can I do it?
Never mind I find this blog
My solution is use the position
FormDataSource callerDataSource;
int position;
callerDataSource = element.args().record().dataSource();
position = callerDataSource.getPosition();
callerDataSource.reread();
callerDataSource.research(true);
callerDataSource.setPosition(position);

Maintaining Row Selection in ASP.NET GridView Control

The Setup:
I currently have a page with a GridView control on it inside of an update panel, using a SqlDataSource. I have a timer setup to update the GridView every X amount of seconds. Typically for what I am testing every time the GridView updates about 4-5 new rows of data are added to the gridview, while the last 4-5 get tossed out. I am only displaying 15 results at a time and will have new results coming in every update.
The Problem:
I allow the user to select the rows, while the GridView is being updated. I am handling this by setting the SelectedIndex property. However, when I select a row and then the grid is updated the row the user selected gets pushed down about 4-5 rows and the data in the previous selected index is selected instead. So where they clicked is selected at this point, not what they clicked.
I need a way to determine, if possible from the SqlDataSource/Gridview, how many new rows have been added to the gridview. OR a way to maintain the selected data by the data in the row and not just the SelectedIndex.
Any help is appreciated, thanks.
RESOLVED:
Ok I went ahead and added a new invisible column to my grid, and am now keep track of the unique ID's selected from the DB. By setting an array before databinding, and comparing that to the new array I get after databinding I was able to use a simple Intersect to determine the number of rows that are the same. Then I used that to determine from the total how many are new this postback.
Just an idea:
I think you can use an invisible column (more specifically an ID column) to store the selected rows' IDs value in the Session object and then after the grid updates, you can retrieve this value(s) and select the row(s) again if they are still present.
If you have custom GridView OnRowUpdating event.
public void GridView_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
Session["CurrIndex"] = GridView.SelectedIndex;//index before insertion
Session["RowCount"] = GridView.Rows.Count;//row count before insertion
//Add new Rows
GridView.SelectedIndex = (Int32)(Session["CurrIndex"]) + ( GridView.Rows.Count - (Int32)(Session["RowCount"]);//update selected index
Session["CurrIndex"] = GridView.SelectedIndex;//restore the index into session
}

Gridview: column with different controls is different modes

Here is my scenario.
I have an objectdatasource-bound gridview where i want to show Students {name, age, class}
name:string, age:int, Class:Foreign key, int
I also want to edit it, but when doing so i want to show a dropdownlist for the class field.
Currently i solve this by
a)creating a view, binding the grid to that view
b) on the editItemTemplate, put a DDL and bind it to the Class table.
What i want to know is if there is a way without involving the view shortcut.
NOTE: this question, Bind column to a different entity source than the gridview is
is somewhat related, but not quite the same thing. in that example, the OP just wanted to show the related data. Since am also updating, i need both the key and the value.

list controls in flex3

i’m new to RIA, Flex.
Currently i’m using Flex 3.
I have some difficulty in my work.
i have three lists and a button.
depending up on the selected items in first two list and after clicking the button i have to disply the items in details list.can any any one help me
thanks in advance
in first list iam displaying names of employees
in second list displaying managers names
then if i select one employee name and one managers name then after clicking button corresponding employee and managers details should be dispplayed in the third list.
this is my work
presently iam unable to post my code
the problem is with initialising the details list and dynamically changing it.
It sounds like your third "list" isn't going to be a list at all, it will be a DataGrid of some kind, or a form with key/value pairs for the common data each employee and manager share.
Presumably your employee and manager lists are populated from a database, and you get more data than the name with each data object. What you need to do is add an event listener which listens for the change event in each of your first two lists. Then you have an event handler that does something with the result. The following just concatenates all the data from each selectedItem (for our imaginary list1 and list2) and puts it into an ArrayCollection, which is then assigned as the dataProvider for a DataGrid named dg:
private function changeHandler(event:DataGridEvent) : void {
var list1Item:Object = list1.selectedItem;
var list2Item:Object = list2.selectedItem;
var ac:ArrayCollection = new ArrayCollection();
for (prop in list1Item) {
ac.addItem({prop:list1Item[prop]});
}
for (prop in list2Item) {
ac.addItem({prop:list2Item[prop]});
}
dg.dataProvider = ac;
}
This is obviously not how you are going to do this, but it serves as an example. More likely you will have certain properties that you are interested in showing, and those are the ones you will add to the dg dataProvider.
This is as helpful as I can be speaking generally, in the absence of specific descriptions and requirements.

How to get data from dynmically created Treeview

I am using ComponentArt Third party controls for ASP.NET 2.0.
Here is the problem I am facing.
I created some ComponentArt.Web.UI.TreeView at runtime on Page_Load.
Now at click event of a button, I want to get values of the selected nodes in the treeview.
Can someone help?
Firstly I'm assuming you have MultipleSelectEnabled set to true to allow the selection of multiple nodes in the TreeView.
If you have that you can use the MultipleSelectedNodes property of the TreeView to get an array of TreeViewNodes.
From here you just need to iterate through the array and use the Value property of the nodes to get what you need.
So essentially something like this should work,
TreeViewNodes[] selectedNodes = treeViewID.MultipleSelectedNodes;
ArrayList values = new ArrayList(selectedNodes.Count);
foreach (TreeViewNode node in selectedNodes) {
values.Add(node.Value);
}
And now you have your selected node values in the ArrayList.

Resources