Click here to Skip to main content
15,891,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hii all

Below is the code i wrote to fill the daragrid

VB
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()



and this is the xaml code

HTML
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 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...
Posted

In xaml code put datagrid itemsource as binding.
 
Share this answer
 
Comments
[no name] 22-Jan-13 4:37am    
didn't get u sry..pls example
[no name] 22-Jan-13 4:43am    
i did that also..but it showing the previous value for the next entries.
e.g. there are 3 item in combo a, b, c
so when i m selecting a grid is blank, when i m selecting b, it showing the data of a so on..
XML
<DataGrid AutoGenerateColumns="False" Height="200" ItemsSource="{Binding}" HorizontalAlignment="Left" Margin="48,63,0,0" Name="dataGrid1" VerticalAlignment="Top" Width="200" />
 
Share this answer
 
Comments
[no name] 22-Jan-13 4:43am    
i did that also..but it showing the previous value for the next entries. e.g. there are 3 item in combo a, b, c so when i m selecting a grid is blank, when i m selecting b, it showing the data of a so on..
[no name] 22-Jan-13 4:52am    
if i do the same code at button click it's working fine..but i need it in selection of combo..
josh-jw 22-Jan-13 4:52am    
please put a break point in
Dim cmd As MySqlCommand = New MySqlCommand("select * from demodata where name='" + ComboBox1.Text + "'", con)
and check whether combobox1.text having the right value.
C#
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
C#
using System.Windows.Threading;
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900