Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Urgent: Changing in runtime ItemsSource property

$
0
0

Hi all of you,

I would like to alter in runtime the dataset assigned to one Grid. Idea here is receiving a parameter which will force to show one Sql table or other..


XAML:


<DataGrid x:Name="dgvArticulos" HorizontalAlignment="Left" Margin="20,80,0,0" VerticalAlignment="Top" Height="175" Width="563"
                 ItemsSource="{Binding Path=V_OR}"  AutoGenerateColumns="false"    AlternatingRowBackground="CadetBlue" 
                  AlternationCount="2">


Code-behind:


This snippet of code loads my Grid:


 connexio = New SqlConnection("Server='ENRIC-PC\ENRIC';Initial Catalog=Talleres;User ID=xxx;Password=xxxx;current language=spanish")



        connexio.Open()


        ada = New SqlDataAdapter("Select * from V_OR", connexio)
        ada.Fill(ds, "V_OR")

        Me.dgvArticulos.DataContext = ds

So that when my parameter equals 1:

    ada = New SqlDataAdapter("Select * from V_OR", connexio)
    ada.Fill(ds, "V_OR")

And when my parameter equals 2:

    ada = New SqlDataAdapter("Select * from V_Vehicles", connexio)
    ada.Fill(ds, "V_Vehicles")


How can I achieve that? I will have to change my XAML property in my GridView declaration, won't I? How???


Thanks indeed for your comments and help provided,


Primary platform is Windows 7 Ultimate 64 bit along with VS 2012/Sql2k8 for WPF/SilverLight projects.



Viewing all articles
Browse latest Browse all 18858

Trending Articles