首页 > 代码库 > 简单的拼成一个内有datagrid的combobox
简单的拼成一个内有datagrid的combobox
<Border Height="22" BorderBrush="DarkGray" BorderThickness="1"> <StackPanel Orientation="Horizontal"> <TextBlock x:Name="TesTextBox" Height="20" Width="154"/> <Button Height="20" Width="14" Click="Button_Click"> <Popup x:Name="Popup1" Height="300" StaysOpen="False"> <Border BorderBrush="DarkGray" BorderThickness="1"> <DataGrid x:Name="TestDataGrid" CanUserReorderColumns = "false" IsReadOnly="True" SelectionChanged="TestDataGrid_SelectionChanged"/> </Border> </Popup> </Button> </StackPanel> </Border>
然后 datagrid进行item赋值
testDatagrid.ItemSource = ...
最后实现一下事件
private void Button_Click(object sender, RoutedEventArgs e) { Popup1.PlacementTarget = TesTextBox; Popup1.Placement= PlacementMode.Bottom; Popup1.IsOpen = true; } private void TestDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e) { TesTextBox.Text = (TestDataGrid.SelectedItem as DataRowView).Row["c_Code"].ToString(); }
搞定!
如图:
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。