0

I'm trying to find an answer to this and I'm pretty new to WPF. It's quite something to get used to and google is not so much of a friend with WPF.

I'm trying to bind a cell item from a listview in Gridview to a simple textbox or label.

Textbox:

<TextBox Text="{Binding ElementName=AD_AccountList, Path=SelectedItem.AD_AccountName}"/>

Listview:

<ListView x:Name="AD_AccountList">
    <ListView.View>
         <GridView>
            <GridViewColumn x:Name="AD_AccountName" Header="Account" DisplayMemberBinding="{Binding AccountName}"/>
        </GridView>
    </ListView.View>
</ListView>

The listview works well and I've been able to bind my object in the background using properties. It fill but I want those textbox to be filled when I select one of the item like this: enter image description here

Johnny Prescott
  • 263
  • 6
  • 23
  • I'm no pro in WPF but seems like you would need a mouse click event to set the value not a binding – JohnChris Jan 26 '17 at 05:45
  • Based on this link: http://stackoverflow.com/a/10219130/6741868, (it uses code-behind, but there is always a way if you want to use MVVM). In the code behind of mouse left button down event, you can set the values for those textboxes. – Keyur PATEL Jan 26 '17 at 06:23

2 Answers2

0

What you need is a master-detail form. I think the data binding to your ListView is already correct. All you need is then bind the selected value to the textboxes. The easiest way is to:

  • bind the Text property of your textboxes to the data used by ListView,
  • bind it using Binding Path name, to the name of the property of the data item. set the ListView's property of IsSynchronizedWithCurrentItem
  • The textboxes are included within a DataTemplate.

For detailed sample about this is available on MSDN Library. It's available in this MSDN link: https://msdn.microsoft.com/en-us/library/aa970558(v=vs.110).aspx

Eriawan Kusumawardhono
  • 4,796
  • 4
  • 46
  • 49
0

Try to bind to the "AccountName" property of the selected item instead of binding to the column name "AD_AccountName":

<TextBox Text="{Binding ElementName=AD_AccountList, Path=SelectedItem.AccountName}"/>

This should work provided that the TextBox and the ListView are in the same namescope.

mm8
  • 163,881
  • 10
  • 57
  • 88