I have a XamDataGrid and a textbox. I want to display selected data from XamDataGrid to that textbox. I tried by many ways but can't. Please support for me how can I do. I used VB.NET and Datasource : SQL server.
Please give me a sample how to do it.
Below is my Xaml
<Window x:Class="donvi" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="donvi" Height="321" Width="623" xmlns:igDP="http://infragistics.com/DataPresenter" Name="Window1" xmlns:c1grid="http://schemas.componentone.com/wpf/C1DataGrid"> <Grid> <igDP:XamDataGrid Name="XamDataGrid1" ScrollingMode="Deferred" SortRecordsByDataType="True" Margin="0,0,220,28"> <igDP:XamDataGrid.FieldLayoutSettings> <igDP:FieldLayoutSettings AutoArrangeCells="Never" RecordSelectorLocation="None" SelectionTypeCell="None" SelectionTypeRecord="Extended" SelectionTypeField="None" AutoGenerateFields="False" AllowAddNew="False" AllowDelete="False" /> </igDP:XamDataGrid.FieldLayoutSettings> <igDP:XamDataGrid.FieldLayouts > <igDP:FieldLayout> <igDP:FieldLayout.Fields> <!-- ============== --> <!-- Example Column --> <!-- ============== --> <igDP:Field Name="donvi" Label="Don vi" Row="0" Column="1"> <igDP:Field.Settings> <igDP:FieldSettings CellClickAction="SelectRecord" AllowGroupBy="True" AllowEdit="False"> </igDP:FieldSettings> </igDP:Field.Settings> </igDP:Field> </igDP:FieldLayout.Fields> </igDP:FieldLayout> </igDP:XamDataGrid.FieldLayouts> </igDP:XamDataGrid> <TextBox Height="23" HorizontalAlignment="Right" Margin="0,90,58,0" Name="TextBox1" VerticalAlignment="Top" Width="120" /> </Grid></Window>
Thank you for your support
Hey, This is a pretty old post...but your posted demo app helped clarify the same issue for me: binding the Text property of a WPF TextBox in XAML.
Really cool product!!
Thanks
:)
It is showing "System.Data.DataRowView", because we pointed you to binding to the DataItem property, which in your case is a DataRowView. As it is a complex object, represented in a TextBox, it will just show the ToString() value of the DataRowView, which is just its type name.
If you want to display more detailed information, you would have to bind to one of the columns of the DataRowView. In your case you have only one, so the binding expression should look like:
Path=ActiveRecord.DataItem.DonVi, ElementName=XamDataGrid1, Mode=OneWay}"
You could also try the following syntax as well
Path=ActiveRecord.Cells[0].Value, ElementName=XamDataGrid1, Mode=OneWay}"
I have put together a small project with this implemented, which you can find here :
Thank you for your support.I did follow by your solutions . But when I click item data , textbox display System.Data.DataRowView. How can display content item ? In this case , I want textbox display "kg" Please see that picture
Thank you very much
quanha said: I edited but it's not successfully.After debug a message displayed : "A TwoWay or OneWay toSource binding cannot work to the read-only property "DataItem" of Type "Infragistics.Window.DataPresenter.DataRecord""
I edited but it's not successfully.After debug a message displayed :
"A TwoWay or OneWay toSource binding cannot work to the read-only property "DataItem" of Type "Infragistics.Window.DataPresenter.DataRecord""
That's because you are binding the Text property of a TextBox which is setup such that it binds twoway by default. If you're binding to a read-only property then you have to set the Mode to OneWay on the binding. i.e. Text="{Binding Path=ActiveRecord.DataItem, ElementName=XamDataGrid1, Mode=OneWay}"
below is my XAML
<Window x:Class="donvi" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="donvi" Height="321" Width="623" xmlns:igDP="http://infragistics.com/DataPresenter" Name="Window1" xmlns:c1grid="http://schemas.componentone.com/wpf/C1DataGrid"> <Grid> <igDP:XamDataGrid Name="XamDataGrid1" ScrollingMode="Deferred" SortRecordsByDataType="True" Margin="0,0,220,28"> <igDP:XamDataGrid.FieldLayouts > <igDP:FieldLayout> <igDP:FieldLayout.Fields> <!-- ============== --> <!-- Example Column --> <!-- ============== --> <igDP:Field Name="donvi" Label="Don vi" Row="0" Column="1"> </igDP:Field> </igDP:FieldLayout.Fields> </igDP:FieldLayout> </igDP:XamDataGrid.FieldLayouts> </igDP:XamDataGrid> <TextBox Height="23" HorizontalAlignment="Right" Margin="0,90,58,0" Text="{Binding Path=ActiveRecord.DataItem, ElementName=XamDataGrid1}" Name="TextBox1" VerticalAlignment="Top" Width="120" /> </Grid></Window>
Below is my VB.NET
Imports System.DataImports C1.WPF.C1DataGridImports System.Data.SqlClientPartial Public Class donvi Dim query As String Dim con As SqlConnection Private Sub Window1_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded con = New SqlConnection con.ConnectionString = "Data Source=ISDEV;Initial Catalog=Quanlybanhang;Integrated Security=True" con.Open() query = "select donvi from donvi" Dim cmd As SqlCommand = New SqlCommand(query, con) Dim ad As SqlDataAdapter = New SqlDataAdapter(cmd) cmd.CommandText = query Dim dt As New DataTable Dim ds As New DataSet ad.SelectCommand = cmd ad.Fill(ds, "donvi") XamDataGrid1.DataSource = ds.Tables(0).DefaultView End SubEnd Class