0

我将实体对象绑定到 gridcontrol

    {
        InitializeComponent();

        gridControl1.DataContext = from q in myEnt.item
                                   from b in myEnt.item_type
                                   where q.item_type_fk == b.item_type_id
                                               select new { q.item_name, q.item,m_type};

    }

哪个运作良好。当我单击网格控件中的一行时,我想在文本框中显示相关数据。我该怎么做?我试过这个:

<TextBox Name="TextBox3" Text="{Binding Path=item_name}"/>

不起作用。

4

2 回答 2

1

试试这个(你需要告诉 TextBox 确切的位置item_name):

<TextBox Name="TextBox3" 
         Text="{Binding ElementName=gridControl1, Path=SelectedItem.item_name}"/>

编辑:

gridControl1似乎是一个GridControl没有SelectedItem属性的 DevExpress(?)。根据此支持文章Change selected item through databinding,此绑定可能会起作用(TableView.FocusedRow):

<TextBox Name="TextBox3" 
         Text="{Binding ElementName=tableView1, Path=FocusedRow.item_name}" />
于 2013-05-28T12:36:48.943 回答
0
<dxr:DXRibbonWindow
x:Class="Eszkoz.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Eszkoz"
xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
xmlns:dxr="http://schemas.devexpress.com/winfx/2008/xaml/ribbon"
xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars"
xmlns:dxbh="http://schemas.devexpress.com/winfx/2008/xaml/bars/internal"
xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
xmlns:dxd="http://schemas.devexpress.com/winfx/2008/xaml/docking"
Title="DXApplication" Height="700" Width="1100"
SnapsToDevicePixels="True" UseLayoutRounding="True"
dx:ThemeManager.ThemeName="Office2013" xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid">
<dxr:DXRibbonWindow.Resources>
    <dx:EntitySimpleDataSource x:Key="EntitySimpleDataSource" ContextType="local:eszkozEntities" dx:DesignDataManager.DesignData="{dx:DesignDataSettings RowCount=5, UseDistinctValues=True}" Path="eszkoz" />
</dxr:DXRibbonWindow.Resources>

<dxb:BarManager x:Name="barManager" dxbh:BlendHelperForBarsAndRibbon.IsDesignControl="true">
    <DockPanel>
        <dxd:DockLayoutManager x:Name="dockLayoutManager">
            <dxd:LayoutGroup>
                <dxd:LayoutPanel ItemWidth="200" Caption="Navigation" Padding="1">
                    <dxg:GridControl AutoPopulateColumns="True" Name="gridControl1" ItemsSource="{Binding}">
                        <dxg:GridControl.View>
                            <dxg:TableView Name="tableView1" ShowTotalSummary="True" />
                        </dxg:GridControl.View>
                    </dxg:GridControl>
                </dxd:LayoutPanel>
                <dxd:LayoutGroup Orientation="Vertical" ItemWidth="4*">
                    <dxd:LayoutPanel Caption="MainView" ItemHeight="3*">
                        <dxd:LayoutGroup Orientation="Vertical">
                            <dxd:LayoutControlItem Caption="Layout Item">
                                <TextBox Height="23" Name="TextBox3" Width="100" Margin="2" HorizontalAlignment="Left" Text="{Binding ElementName=gridControl1, Path=SelectedItem.item_name}"/>
                            </dxd:LayoutControlItem>
                        </dxd:LayoutGroup>
                    </dxd:LayoutPanel>
                    <dxd:LayoutPanel Caption="DetailView" ItemHeight="2*"></dxd:LayoutPanel>
                </dxd:LayoutGroup>
            </dxd:LayoutGroup>
        </dxd:DockLayoutManager>
    </DockPanel>
</dxb:BarManager>

于 2013-05-28T13:44:59.470 回答