我有select语句,显示datagrid中的所选项目。
cmdSel.CommandText = "select id,Name,TypeID,StatusID from document where Contains([Context],'FormsOf (INFLECTIONAL, \"" + TextBoxSearch.Text + "\")')";
<WpfToolkit:DataGrid IsTextSearchEnabled="True" IsReadOnly="True" CanUserSortColumns="True" AutoGenerateColumns="False" Name="DataGrid1"
ItemsSource="{Binding Path=MainSearchBinding}" SelectionChanged="DataGrid1_SelectionChanged">
<WpfToolkit:DataGrid.Columns>
<WpfToolkit:DataGridTextColumn Header="Номер" Width="63" Binding="{Binding id}" IsReadOnly="false" />
<WpfToolkit:DataGridTextColumn Header="Название" Width="*" Binding="{Binding Name}" IsReadOnly="false" />
</WpfToolkit:DataGrid.Columns>
我有另一个用richtextbox的用户控件。我想通过点击datagrid中的数据来显示richtextbox上的特定数据。
我尝试了我在这里找到的东西,它没有帮助我。请指点我。提前谢谢。
答案 0 :(得分:1)
他是我的问题的答案,有人可能需要。首先点击鼠标我正在寻找id然后根据该ID选择Context,这里是代码
private void OnMouseClick(object sender, MouseButtonEventArgs e)
{
IList rows = DataGrid1.SelectedItems;
DataRowView row = (DataRowView)DataGrid1.SelectedItems[0];
int a = (int)row["ID"];//It is returning the id of selected row
DocumentView docview = new DocumentView();
commProc = new SqlCommand("SELECT Context from Document where ID='" + a + "'", MainWindow.conn);//Depending on ID I am selecting context.
SqlDataReader dr = commProc.ExecuteReader();
string str;
FlowDocument document = new FlowDocument();
Paragraph paragraph = new Paragraph();
if (dr.Read())
{
str = (string)dr["Context"];
paragraph.Inlines.Add(new Bold(new Run(str)));
document.Blocks.Add(paragraph);
docview.RBox.Document = document;
}
dr.Close();
var tabControl = (sender as DataGrid).FindParent<TabControl>();
tabControl.Items.Add(new TabItem() { Header = "Документ", Content = docview, IsSelected = true });
}