Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6592301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:32:13+00:00 2026-05-25T17:32:13+00:00

I have a datagrid within a view <Grid x:Name=LayoutRoot Background=White Width=600 MaxHeight=150> <sdk:DataGrid x:Name=grid1

  • 0

I have a datagrid within a view

<Grid x:Name="LayoutRoot" Background="White" Width="600" MaxHeight="150">
    <sdk:DataGrid x:Name="grid1" ItemsSource="{Binding Persons}" SelectedItem="{Binding MyList, Mode=TwoWay}">
    </sdk:DataGrid>
</Grid>

Within my ViewModel I have the following code

private ObservableCollection<string> myList;
    public ObservableCollection<string> MyList
    {
        get { return myList; }
        set
        {
            myList = value;
            NotifyPropertyChanged(vm => vm.MyList);
        }

And for the DG

 private ObservableCollection<Person> person;    
    public ObservableCollection<Person> Persons
    {
        get { return person; }
        set
        {
            person = value;
            NotifyPropertyChanged(vm => vm.Persons);
        }
    }

I was hoping from the View I could bind the selected item(row) of the datagrid to the MyList collection within my view model (Maybe IList vs OC?). I only need one value from the selected row such as address or zip. But do I need to pass the entire collection of can I get just one cell value into the view model another way?

For example here is the class I am using to populate the data grid

        public void CreateList()
    {
        Person p = new Person();
        p.FirstName = "Bob";
        p.LastName = "Jones";
        p.Address = "123 Main Street";
        p.City = "Wilmington";
        p.State = "NC";
        p.Zip = "12345";


        Person p1 = new Person();
        p1.FirstName = "Sue";
        p1.LastName = "Smith";
        p1.Address = "1222 Main Street";
        p1.City = "Tampa";
        p1.State = "FL";
        p1.Zip = "12345";

        Person p2 = new Person();
        p2.FirstName = "Chris";
        p2.LastName = "Jones";
        p2.Address = "234 Water Street";
        p2.City = "Dallas";
        p2.State = "TX";
        p2.Zip = "22222";

        Person p3 = new Person();
        p3.FirstName = "Andy";
        p3.LastName = "Jones";
        p3.Address = "434 Main Street";
        p3.City = "Columbia";
        p3.State = "SC";
        p3.Zip = "12345";

        ObservableCollection<Person> Result = new ObservableCollection<Person>();
        Result.Add(p);
        Result.Add(p1);
        Result.Add(p2);
        Result.Add(p3);

        Persons = Result;          
    }

This class is fired when the view model is loaded. I would like to be able to select the third row of data and only pass the address value back to the VM. My inital thought was to pass the entire selected row back to the vm and then extract the address from that collection.

Using the selectedItem Binding does not work, selecting a row never triggers the inotify event in the vm so I know the collection is not being updated unless I click in the DG and then outside of it which only passes a null value. Secondly, is there a more effient way to do this vs. using the code behind to pull a value and then pass it to the VM? I had thought of using selection changed event within view and then set the column value to a bound field that is passed to the vm but this seems hacky.

Thanks for any suggestions or ideas.

-cheers

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T17:32:14+00:00Added an answer on May 25, 2026 at 5:32 pm

    Update
    The current approach I am taking for this is within the code behind of the view I have the following

            private void grid1_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            Person selectedPerson = grid1.SelectedItem as Person;
            textholder.Text = selectedPerson.Address;
        }
    

    Then within the view I have a text field

     <TextBlock x:Name="textholder" Text="{Binding SelectedID, Mode=TwoWay}"/>
    

    Which is bound to the SelectedID property within the VM

    This works and gets the value to the VM. This just seems wierd in implementation (but it is a lot less code that using commands and command parameters 🙂 ) . I’d welcome any other ideas.

    -cheers

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have DataGrid with dataBinding: <sdk:DataGrid x:Name=colorGrid Height=160 Margin=0,5,0,10 RowHeight=40 AutoGenerateColumns=False > <sdk:DataGrid.Columns> <sdk:DataGridTextColumn
I have the following XAML: <UserControl.Resources> <local:MainPageViewModel x:Key=ViewModel /> </UserControl.Resources> <Grid x:Name=LayoutRoot DataContext={Binding Source={StaticResource
I have a datagrid called DataGridView1, column A contains a name, column B contains
I have some problem to access the Window's DataContext from within a DataGrid. The
I've got a DataGrid control that's within a Grid layout container, and I can't
Currently i have a datagrid view that displays names in the 1st columnnd in
I have a primefaces dataList within a primefaces dataGrid but I'm having issue mapping
I Have a bound Data grid view to the below Questions Class: public class
<mx:DataGrid x=10 y=10 width=180 height=302 id=dgActions dataProvider={actionCollection}> <mx:columns> <mx:DataGridColumn headerText=Action dataField=name/> <mx:DataGridColumn headerText= dataField=setting
So I have a custom control: <Grid> <StackPanel HorizontalAlignment=Center Orientation=Vertical> <CheckBox x:Name=chkboxListen HorizontalAlignment=Center Checked=chkboxListen_Checked

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.