WPF:如何将网格单元格发送到文本框 [英] WPF:How Send Grid Cell To Textbox
问题描述
单击详细信息"按钮时如何将网格的内容发送到文本框
这是网格视图代码:
我有3列,每行1个按钮
我有3个文本框
how can we send the grid''s content to textboxes when we click on the Details button
this is the grid view code :
i have 3 columns and 1 button for each row
and i have 3 textboxes
<telerik:RadGridView Grid.Row="1" Name="dtgAttachment" AutoGenerateColumns="False" EnableRowVirtualization="True" ItemsSource="{Binding}" RowDetailsVisibilityMode="VisibleWhenSelected" >
<telerik:RadGridView.Columns>
<telerik:GridViewColumn>
<telerik:GridViewColumn.CellTemplate>
<DataTemplate>
<telerik:RadButton Content="Details" Name="btnDetails" Click="btnDetails_Click" IsEnabled="True" CommandParameter="{Binding}"/>
</DataTemplate>
</telerik:GridViewColumn.CellTemplate>
</telerik:GridViewColumn>
<telerik:GridViewDataColumn x:Name="dtgAttachmentId" DataMemberBinding="{Binding Path=attachment_id}" Header="{x:Static locala:ResourceProject.lblAttachmentId}" Width="SizeToHeader" />
<telerik:GridViewDataColumn x:Name="dtgName" DataMemberBinding="{Binding Path=attachment_name}" Header="{x:Static locala:ResourceProject.lblNameAttachment}" Width="SizeToHeader" />
<telerik:GridViewDataColumn x:Name="dtgPrice" DataMemberBinding="{Binding Path=attachment_price}" Header="Price" Width="SizeToHeader" />
</telerik:RadGridView.Columns>
</telerik:RadGridView>
请帮助.......
please help.......
推荐答案
非常感谢您提供解决方案
看
我找到解决办法
我删除按钮
我只有带有3列和3个textBox的GridView
我在GridView中使用事件MouseDoubleClick
像这样:
thank you very much for solution
look
i find solution
i remove button
and i have just GridView with 3 columns and 3 textBox
i use event MouseDoubleClick in GridView
like this:
<telerik:RadGridView Grid.Row="1" Name="dtgAttachment" AutoGenerateColumns="False" EnableRowVirtualization="True" ItemsSource="{Binding}" RowDetailsVisibilityMode="VisibleWhenSelected" MouseDoubleClick="dtgAttachment_MouseDoubleClick" >
<telerik:RadGridView.Columns>
<telerik:GridViewColumn>
</telerik:GridViewColumn>
<telerik:GridViewDataColumn x:Name="dtgAttachmentId" DataMemberBinding="{Binding Path=attachment_id}" Header="{x:Static localo:Resource.dtgAttachmentId}" Width="SizeToHeader" />
<telerik:GridViewDataColumn x:Name="dtgName" DataMemberBinding="{Binding Path=attachment_name}" Header="{x:Static localo:Resource.dtgName}" Width="SizeToHeader" />
<telerik:GridViewDataColumn x:Name="dtgPrice" DataMemberBinding="{Binding Path=attachment_price}" Header="{x:Static localo:Resource.dtgPrice}" Width="SizeToHeader" />
</telerik:RadGridView.Columns>
</telerik:RadGridView>
然后在代码C#中编写此代码
and in Code C# i write this Code
private void dtgAttachment_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
attachment_tab a = dtgAttachment.SelectedItem as attachment_tab;
if (a != null)
{
var g = from d in Program.Context.attachment_tab
where d.attachment_id == a.attachment_id
select d;
txtbAttachmentId.Text = g.FirstOrDefault().attachment_id.ToString();
txtNameAttachment.Text = g.FirstOrDefault().attachment_name;
txtPriceAttachment.Text = g.FirstOrDefault().attachment_price.ToString();
}
else
MessageBox.Show("There is no data");
}
谢谢您的帮助...........
thank you for help...........
解决方案1
在具有"attachment_id","attachment_name","attachment_price"属性的类中定义SelectCommand.
Solution 1
Define SelectCommand in class where you have ''attachment_id'', ''attachment_name'', ''attachment_price'' properties.
<telerik:RadButton Content="Details" Name="btnDetails" Command="{Binding SelectCommand}" IsEnabled="True" CommandParameter="{Binding}"/>
在持有上述集合的父项中定义SelectCommand执行.将父SelectCommand传递给上述集合的单个对象.
在命令执行过程中,将通过CommandParameter绑定接收的数据作为DataContext分配给其他TextBoxes的Parent.
注意:我假设您在这里遵循MVVM模式.
解决方案2
通过将btnDetails_Click事件处理程序中的CommandParemeter强制转换为RadButton,从发件人中提取它.
将此CommandParemeter作为DataContext传递,以控制谁托管所有其他文本框.
Define SelectCommand execution in parent who is holding above collection. Pass the parent SelectCommand to individual object of above collection.
In your command execution, assign data you are receiving through CommandParameter binding as DataContext to Parent of your other TextBoxes.
Note: I am assuming you are following MVVM pattern here.
solution 2
Extract CommandParemeter in btnDetails_Click event handler from sender by casting it to RadButton.
Pass this CommandParemeter as DataContext to control who is hosting all other textboxes.
连接sql数据库通过给文本框值查看girdviewdetails中的所有数据
在javacoding
connecting sql databse throuh give textbox value view all data in girdviewdetails
in javacoding
这篇关于WPF:如何将网格单元格发送到文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!