Click here to Skip to main content
15,891,375 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to show datagrid if row of other datagrid is selected
XAML
XML
<datagrid x:name="Concours" isreadonly="True" autogeneratecolumns="True" canuserreordercolumns="True" canuserresizecolumns="True" canuserresizerows="False" canusersortcolumns="True" selectionchanged="Concour_SelectionChanged" horizontalalignment="Left" margin="288,48,0,0" verticalalignment="Top" height="345" width="652" xmlns:x="#unknown">
            <datagrid.rowdetailstemplate>
                <datatemplate>
                    <datagrid x:name="{Binding Epreuve}" isreadonly="False" canuseraddrows="True" canuserdeleterows="True" canuserreordercolumns="True" canuserresizecolumns="True" canusersortcolumns="True" canuserresizerows="False" rowdetailsvisibilitymode="VisibleWhenSelected">
                        <datagrid.columns>
                            <datagridtextcolumn header="Code" binding="{Binding Code}" />
                            <datagridtextcolumn header="Désignation" binding="{Binding Designation}" />
                            <datagridtextcolumn header="Coefficient" binding="{Binding Coef}" />
                            <datagridtextcolumn header="Date" binding="{Binding Date}" />
                        </datagrid.columns>
                    </datagrid>
                </datatemplate>
            </datagrid.rowdetailstemplate>
        </datagrid>


What I have tried:

XAML
C#
C#
private void Concour_SelectionChanged (object sender, EventArgs e)
{
    //Get the First Cell Value
    DataTable dt = new DataTable();
    dt = ((DataView)Concours.ItemsSource).ToTable();
    List<string> L = new List<string>();
    foreach (DataRow row in dt.Rows)
    {
        L.Add((String)row[0]);
    }
    int row_number = Concours.SelectedIndex;
    //Connect To DataBase (gestion_concour)
    MySqlConnectionStringBuilder builder = new MySqlConnectionStringBuilder();
    builder.Server = "127.0.0.1";
    builder.UserID = "root";
    builder.Password = "root";
    builder.Database = "gestion_concour";
    MySqlConnection connection = new MySqlConnection(builder.ToString());
    connection.Open();
    //Fill Epreuve
    String q = "SELECT * FROM gestion_Concour.concour WHERE Code = @Code";
    MySqlCommand cmd = new MySqlCommand(q, connection);
    cmd.CommandText = q;
    cmd.Parameters.AddWithValue("@Code", L[row_number]);
    cmd.ExecuteNonQuery();
    MySqlDataAdapter DA = new MySqlDataAdapter(cmd);
    DataTable DT = new DataTable("Epreuve");
    DA.Fill(DT);
    Epreuve.ItemSource = DT.DefaultView;
    DA.Update(DT);
    connection.Close();
}

ERROR :The name 'Epreuve' does not exist in the current context
Posted
Updated 28-Apr-16 2:23am
v4

1 solution

Hi, change inner datagrid name x:Name="{Binding Epreuve}" as x:Name="Epreuve",
XML
<datagrid x:Name="Epreuve" isreadonly="False" canuseraddrows="True" canuserdeleterows="True" canuserreordercolumns="True" canuserresizecolumns="True" canusersortcolumns="True" canuserresizerows="False" rowdetailsvisibilitymode="VisibleWhenSelected">
 
Share this answer
 
v2
Comments
GHOMRANI ILYES 28-Apr-16 8:37am    
Still the same probleme
GHOMRANI ILYES 28-Apr-16 8:43am    
I think i have to do somthing like that "ItemSource = "{Binding Epreuve}"
VR Karthikeyan 28-Apr-16 10:27am    
Its not ItemSource, it is ItemsSource

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