在组合项目选择中填写数据网格需要帮助 [英] need help in filling datagrid on combo item selection
本文介绍了在组合项目选择中填写数据网格需要帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hii all
以下是我写的填充红色的代码
Hii all
Below is the code i wrote to fill the daragrid
con.Open()
Dim cmd As MySqlCommand = New MySqlCommand("select * from demodata where name='" + ComboBox1.Text + "'", con)
Dim ds As New DataSet("demodata")
Dim da As MySqlDataAdapter = New MySqlDataAdapter(cmd)
da.Fill(ds)
Datagrid1.ItemsSource = ds.Tables(0).DefaultView
con.Close()
这是xaml代码
and this is the xaml code
ComboBox Height="23" HorizontalAlignment="Left" Margin="344,302,0,0" Name="ComboBox1" VerticalAlignment="Top" Width="120" ItemsSource="{Binding}">
<ComboBoxItem Content="ss" />
<ComboBoxItem Content="s" />
</ComboBox>
i在DB中有s和ss名称,但是当我选择它没有显示我的值时在网格中..
请告诉我错误...
i have both s and ss names in DB but when i m selecting its not showing me the values in the grid..
please tell me the error...
推荐答案
在xaml代码中将datagrid itemsource作为绑定。
In xaml code put datagrid itemsource as binding.
<DataGrid AutoGenerateColumns="False" Height="200" ItemsSource="{Binding}" HorizontalAlignment="Left" Margin="48,63,0,0" Name="dataGrid1" VerticalAlignment="Top" Width="200" />
private void comboxsample_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
Dispatcher.BeginInvoke(new Action(selectItem), DispatcherPriority.Background);
}
private void selectItem()
{
string s = this.comboxsample.Text;
}
使用命名空间
use namespace
using System.Windows.Threading;
这篇关于在组合项目选择中填写数据网格需要帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文