访问其他DataGrid.RowDetailsTemplate中的DataGrid

时间:2016-04-28 00:08:55

标签: c# datagrid

我有两个DataGrid ConcourEpruve我想要Epreuve显示选择Concour的行时...我的问题是如何访问DataGrid Epreuve以从MySQL填充。

这是我试过的

XAML

<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">
        <DataGrid.RowDetailsTemplate>
            <DataTemplate>
                <DataGrid x:Name="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>

CS

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();
    }

我得到了这个错误

  

名称&#39; Epreuve&#39;在当前上下文中不存在

1 个答案:

答案 0 :(得分:1)

我更改了public class ReadFromFile { public static void main(String[] args) throws Exception { StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); env.getConfig().disableSysoutLogging(); env.getConfig().setRestartStrategy(RestartStrategies.fixedDelayRestart(4, 10000)); env.enableCheckpointing(5000); // create a checkpoint every 5 secodns env.setParallelism(6); File dir = new File(System.getProperty("user.dir") + "/cep"); ///data/tools/devlop/idea/flink-test/cep System.out.println(dir.getPath()); if (!dir.exists()) { dir.mkdir(); } //read data from local file //it looks like below //016-04-20T00:04:35.155Z","10.170.236.226","<p2-sidekiq> 2016-04-20T00:04:31.415Z 4982 TID-oxvsomclk AlterationWorker JID-34683abcb587e008153ce458 INFO: start" final DataStream<String> messageStream =env.readTextFile("file://"+dir); // filter data DataStream<String> da = messageStream.filter(new FilterFunction<String>() { @Override public boolean filter(String value) throws Exception { if (value !=null && value.contains(" JID-") && value.contains("INFO: ")) { return true; } return false; } }); // format data DataStream<Tuple4<String, String, String,String>> t3 = da.map(new MapFunction<String, Tuple4<String, String,String, String>>() { @Override public Tuple4<String,String, String, String> map(String value) throws Exception { String[] info = value.split("INFO: "); if (info.length == 2) { String[] jid = info[0].split(" JID-"); if (jid.length == 2){ return new Tuple4<String, String, String,String>(jid[0],jid[1].trim(), info[1],""); } } return null; } }); //make tuple to event DataStream<Event_d> input = t3.map(new MapFunction<Tuple4<String, String,String, String>, Event_d>() { @Override public Event_d map(Tuple4<String, String,String, String> value) throws Exception { return new Event_d(value.f0, value.f1, value.f2,value.f3); } }).keyBy(new KeySelector<Event_d, String>() { @Override public String getKey(Event_d value) throws Exception { return value.getName(); } }); // design pattern contains (start --> SendThirdPartWorker --> done) Pattern<Event_d, ?> pattern= Pattern.<Event_d>begin("start").where( new FilterFunction<Event_d>() { @Override public boolean filter(Event_d value) throws Exception { return value.getPrice().contains("start");//&& MD5Util.MD5(value.getMd5())==; } }).next("send").where(new FilterFunction<Event_d>() { @Override public boolean filter(Event_d value) throws Exception { return value.getPrice().contains("SendThirdPartWorker");//&& jidMap.get(value.getName())==value.getName(); } }).followedBy("done").where(new FilterFunction<Event_d>() { @Override public boolean filter(Event_d value) throws Exception { return value.getPrice().contains("done") ;//&& a; } }).within(milliseconds(1000)); final long mi1 = new Date().getTime(); DataStream<String> result = CEP.pattern(input, pattern).select( new PatternSelectFunction<Event_d, String>() { @Override public String select(Map<String, Event_d> pattern) { StringBuilder builder = new StringBuilder(); builder.append(dataComt(new Date().getTime(),mi1)+" "+pattern.get("start").getName()) .append(" -- ").append(pattern.get("send").getPrice()); //.append("--").append(pattern.get("done").getPrice()); return builder.toString(); } }); result.writeAsText(dir + "result", FileSystem.WriteMode.OVERWRITE); env.execute("Read from Kafka custom"); } public static String dataComt(long current,long last) { long c = (current-last)/1000; return "\"read "+c+"s \""; } } 并使用Concour_SelectionChnged

<强> CS

Concour_LoadRowDetails