.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
MarieAdela
Imran Ghani
Post New Web Links

Get SelectedItems From DataGrid Using MVVM In Silverlight

Posted By: Asim Sajjad     Posted Date: July 18, 2011    Points: 2   Category :Silverlight
 
In this post what I want to learn and to share something like how to get the selected items from the data grid control of the Silver light using MVVM. You can see the main output of the example code in the Image 1, here you can see that I have a data grid control and three button with label Add, edit and delete records. Let me explain you what is happening in the example code, user is allowed to select multiple record from the grid and the selected records Ids are displayed in the "Selected Ids" area. If user select only one record then add and edit buttons are enabled and if records are more then one then add and edit buttons are disabled. Similarly If number of selected item count is shown in the delete button text.


View Complete Post


More Related Resource Links

WPF Datagrid multiple selecteditems in MVVM

  

Hi,

I have a Datagrid (VS 2010 .NET 4) and using MVVm pattern in my application. I need to build a context menu that allows to perform an operation on one or more selected rows of the underling datagrid. I don't understand how to send the list of selected items to the view model from the view. Can anybody help me out.

Thanks

Vijay


Selecting One Checkbox Control In DataGrid Control Using MVVM Using Silverlight

  
In this post I will show you how to select single check-box control when you have single check-box control in each row of the datagrid control. As you all know that check-box controls are normally used for the multiple selection and radio buttons are used for single selection. But there are sometimes requirement that control should be check-box and selection should be single. Mean if user view data in the datagrid control then he/she should only select one check-box at a time not more then one. Main page is shown in the Image 1. Here you can see that I have placed check-box control in the first column of the datagrid control which I have also highlighted.

delete button in datagrid in MVVM not working

  
i have a datagrid. i have added a delete button as data template. but on button click, the event is not firing .  <sdk:DataGrid AutoGenerateColumns="False"                       Height="94"                       HorizontalAlignment="Left"                       Margin="0,53,0,0"                       Name="dataGrid1" VerticalAlignment="Top" Width="560"                       ItemsSource="{Binding SelectedComponentInfo.FilterComponentCriteriaMapping}"                       SelectedItem="{Binding SelectedMappingInfo, Mode=TwoWay}" CanUserReorderColumns="True" CanUserResizeColumns="True" DataContext="{Binding}">    

delete button in datagrid in MVVM not working

  
hi all, i am using VS 2010 with silverlight 4.0. i have a datagrid. i have added a delete button as data template. but on button click, the event is not firing .  <sdk:DataGrid AutoGenerateColumns="False"                       Height="94"                       HorizontalAlignment="Left"                       Margin="0,53,0,0"                       Name="dataGrid1" VerticalAlignment="Top" Width="560"                       ItemsSource="{Binding SelectedComponentInfo.FilterComponentCriteriaMapping}"                       SelectedItem="{Binding SelectedMappingInfo, Mode=TwoWay}" CanUserReorderColumns="True" CanUserResizeColumns="True" DataCon

delete button in datagrid in MVVM not working

  
hi all, i am using VS 2010 with silverlight 4.0. i have a datagrid. i have added a delete button as data template. but on button click, the event is not firing .  <sdk:DataGrid AutoGenerateColumns="False"                       Height="94"                       HorizontalAlignment="Left"                       Margin="0,53,0,0"                       Name="dataGrid1" VerticalAlignment="Top" Width="560"                       ItemsSource="{Binding SelectedComponentInfo.FilterComponentCriteriaMapping}"                       SelectedItem="{Binding SelectedMappingInfo, Mode=TwoWay}" CanUserReorderColumns="True" CanUserResizeColumns="True" DataCon

Refresh Silverlight datagrid

  
In a Silverlight page I have a datagrid (items loaded from a SP list) and below it a dataform that lets the user make edits to the items displayed in the datagrid when a row is selected from the datagrid.  However, when a user makes an edit to an item using the dataform, the datagrid doesn’t get refreshed when I re-query (via CAML) the SP list to refresh the datagrid.  Only if I change another item in the dataform, does the datagrid then refresh as expected. Code when I Edit the list item in the dataform: public void EndEdit() { ClientContext context = new ClientContext(ApplicationContext.Current.Url); context.Load(context.Web); _skills = context.Web.Lists.GetByTitle("Skills_NewRequest").GetItemById(skillId); _skills["TimeStamp"] = TimeStamp; _skills["Parent"] = Parent; _skills.Update(); context.ExecuteQueryAsync(OnRequestSucceeded, OnFailListener); } private void OnRequestSucceeded(Object sender, ClientRequestSucceededEventArgs args) { Deployment.Current.Dispatcher.BeginInvoke(BindData); } private void BindData() { //MessageBox.Show("Your request has been submitted!"); }   And here’s the code for refreshing the datagrid: private void dataFormNewPending_EditEnding(object sender, DataFormEditEn

delete more than one row in datagrid in silverlight 3

  
I tried to delete more than one row in datagird in silverlight, using chechbox checked, and binding to itemsource. I have following code: ---------------------- Orderlist = (System.Collections.ObjectModel.ObservableCollection<SilverlightWebService.Order>)dgOrders.ItemsSource;  System.Collections.ObjectModel.ObservableCollection<SilverlightWebService.Order> orderlist1 = new System.Collections.ObjectModel.ObservableCollection<ConcourseSilverlight.SilverlightWebService.Order>(); foreach (SilverlightWebService.Order aorder in Orderlist) { if (aorder.CheckedItem == false) orderlist1.Add(aorder); }  dgOrders.ItemsSource = orderlist1; -------------- DataGrid will be repopulated. But values selected will be defaut ones, that means data selected is not retained. may be itemsource is changes. how can I resolve this        

Binding DataGrid RowDetailTemplate Using MVVM

  
In this post I will show you how you can bind the RowDetailTemplate of the data grid using the MVVM pattern. Below are the image of the sample code here you can see the default page in Image 1 and when user click on any of the record then detail of the record is shown in the RowDetailTemplate which also consist of the data grid control which you can see in the Image 2.

combobox in datagrid with MVVM Pattern

  

Hi

  i have requirement that, datagrid has a two column one is text column and other is combo box, combo box contain 2 column including checkbox. once i click the checkbox in combobox, resepective first column value need to display in combo box selected item and second column values need to display in first column of the data grid.

  I have used following code in xmal

 

<DataGrid x:Name="dgMixture"  VerticalAlignment="Top"  Width="250"
                      RowHeight="25"  GridLinesVisibility="Vertical" HeadersVisibility="Column" IsReadOnly="True"  AutoGenerateColumns="False"
                      HorizontalAlignment="Left" CanUserAddRows="False" ItemsSource="{Binding CompanyItemsCV}"   >
                <DataGrid.Columns>                   
       &nb

Cannot Automatically Refresh WPF Datagrid (MVVM / Prism)

  

I'm developing MVVM application. I bind the DataGrid ItemsSource to a ObservableCollection in the ViewModel code. Every user control (eg. TextBox, Label, etc) in the UI except the DataGrid works fine. When the PropertyChanged event is fired, the value is displayed correctly. But not in the DataGrid, I use TwoWay mode, but it seems that the DataGrid never refresh itself. The DataGrid content is refreshed only when I try to sort any DataGrid column.

ViewModel

public ObservableCollection<CartItem> Cart
{
	get	{
		return cart;
	}
	set	{
		cart = value;
	}
}
public ObservableCollection<CartItem> cart;

public CartItem CurrentCartItem
{
	get	{
		return currentCartItem;
	}
	set	{
		currentCartItem = value;
		// Update the Price value programatically, 
		// It works fine when this value is bound to a common control such as TextBlock
		currentCartItem.Price = CurrentCartItem.Quantity * CurrentCartItem.PricePerUnit;
		NotifyPropertyChanged(

WPF DataGrid Style Templates to make it look like the Silverlight DataGrid

  

Hi,

Many of you might have noticed that the WPF DataGrid looks very blah compared to the Silverlight DataGrid.

Here are the WPF DataGrid Screenshot and Silverlight DataGrid Screenshot.

See how in the Silverlight DataGrid the lines are better, there are alternating row backgrounds and the selected row also looks better.

I am surprised the WPF DataGrid doesn't use the same styles by default as the Silverlight.

Has anyone styles the WPF DataGrid to make it look like the Silverlight DataGrid and if so can you share the templates with me?

Or is there a built-in theme in WPF DataGrid that looks close to the Silverlight DataGrid?

Thanks

Cooper


Nested DataGrid - Accessing parent selected row from child in MVVM

  
Hi All,

I have a nested datagrid. The child datagrid is inside the RowDetailsTemplate.
I have expander and collapse button to open the child datagrid. When i select the expander/collapse button, the row of the parent datgrid gets selected and the child datagrid is loaded with data. Next, i select the child datagrid row. So the problem is when i am selecting the child datagridrow, the parent datagrid row selection should be deselected.

This needs to be achieved in MVVM

Please help.

WPF 4 Datagrid CRUD MVVM

  

Hello !

I`m looking for a good practice of CRUD operations( MVVM pattern  with WPF 4 Datagrid and List <T>  (observable collection ))  -  all examples not so good or inconvinient

I have  GetAllUsers,  AddUSER, UpdateUSER, DeleteUSER methods ( WCF methods )

 

class User

{

Guid ID;

string Login;

string Password;
Employee Employee;
}




 

Thanks for any suggestion!

 



Silverlight - Dynamically generating a table for datagrid

  

Hi there,

 

I am parsing a table in my Silverlight application. Lets say the table is as follows

*   A   B   C

A   1   2   3

B   3   4   6

C   2   2  2

I do not know before hand the column names, how many columns there are so, as far as I know, I can only see a solution to presenting this as a table with the traditional unbound data strategy as in windows forms.  However, my solution is in Silverlight, so I necessarely need to bind to an object.  But as said, I do not know the object properties, so I got stuck.  Please help; this seems like it should be very simple to display a parsed table.

 

Many thanks. 

 


Binding Command Inside DataGrid Using MVVM

  
In this post I will show you how to bind the commands inside the data grid control using MVVM pattern. For this post I have continue my last post which is used to explain the data pager using MVVM. For this post I have added DelegateCommand class which is added in the Classes folder. I have only one command in the viewModel (with the name HomeViewModel and is located in the ViewModel folder). The view for the Home is located in the View folder. Here you can see that I have added the HomeViewModel as resource in the home view which you can see in the Image 1.

DataPager Using MVVM in Silverlight 4

  
In this short post I will show you how to use the DataPager control using MVVM pattern in silverlight. I have develop navigation application for this example which you can see as shown in the Image 1. Here you can see that I have two control in the home screen one is the DataGrid and the second one is the DataPager control.

How To Use DataTriggers In Silverlight DataGrid

  
In this short post I will show you how you can use DataTriggers in datagrid control DataGridTemplateColumn. This was one of the questions when reading one of the forum to change persform some sort of functionality depending on the value of the property. Out of the example code can be seen in the Image 1 here you can see that I have used the DataTrigger for the Subscribed which is nullable Boolean type, mean It hold true , false and null value.
Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend