Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Windows WPF VB.NET
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()
 

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 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 21-Jan-13 23:26pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

In xaml code put datagrid itemsource as binding.
  Permalink  
Comments
Snehasish Nandy at 22-Jan-13 4:37am
   
didn't get u sry..pls example
Snehasish Nandy at 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..
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

<DataGrid AutoGenerateColumns="False" Height="200" ItemsSource="{Binding}" HorizontalAlignment="Left" Margin="48,63,0,0" Name="dataGrid1" VerticalAlignment="Top" Width="200" />
  Permalink  
Comments
Snehasish Nandy at 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..
Snehasish Nandy at 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 at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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;
  Permalink  
v2

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



Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 22 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100