打开2 Windows(WPF)与其他数据 [英] Open 2 Windows (WPF) with other datas

查看:52
本文介绍了打开2 Windows(WPF)与其他数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我的问题:

我有一个程序,在这里你可以看到一个datagrid(与SQL数据库绑定) )。

网格是DevExpress GridControl。

现在当你双击这个网格中的一行时,它会打开一个新窗口。新窗口成为selectet / clicked行作为参数。

现在你可以做很多事情,在数据库中写入数据......一切都很棒。当我做一个SQL命令时,我需要来自这个人的ID,我有这个参数。



现在问题:当我打开这个表格时2时间,它不起作用...

例如:

1.启动程序

2.从网格中选择一个人 - >新窗口打开

3.从网格中选择其他人 - >再次打开新窗口

4.亲自做一些事情,并关闭它

5.在另一个人身上做点什么。这里没有保存这些更改!!!!!



问题是,第二次双击,覆盖了口渴人的身份证明了新ID ...



如何打开2个窗口并知道哪个ID在哪个窗口?



我希望你知道我的意思是,可以帮助我或者给我一个小费我必须做的...



谢谢

Hello,

My problem:
I have a programm, in this you can see a datagrid (binding with a SQL database).
The grid is a DevExpress GridControl.
now when you double click on a row in this grid, it open a new Window. The new Window becomes the selectet/clicked row as parameter.
Now you can do much things, write datas in the Database... that all works fantastic. when i do a SQL-command, i need the ID from this person, this i have, from the parameter.

Now the Problem: When i open this form 2 times, it doesn´t work...
For example:
1. Start the Program
2. select a person from the Grid -> new window open
3. select an other person from the Grid -> again new window open
4. do something in person 1, and close it
5. do something in the other person. Here this changes are not saved!!!!!

The problem is, that the second doubleclick, overrides the ID from the thirst person wird the new ID...

How i can open 2 windows and know which ID ist which window?

I hope you know what i mean, and can help me or give me a tip what i must do...

Thanks

推荐答案

这个问题的简便解决方案是创建一个私有字段来存储ID,并在创建新窗口时将参数传递给窗口,然后再显示它。



A short-hand solution to this problem is to create a private field to store the ID, and while creating the new Window pass the parameter to the window before showing it.

public class MyWindow : Window {
   // Field
   private int ID { get; set; }

   // Constructor
   public MyWindow() {
      InitializeComponent();
   }

   public MyWindow (int id) { 
      ID = id; // set the ID
      InitializeComponent();
   }
}





现在,每个实例都会拥有不同的ID。然后,您可以使用它来区分Window的实例。



Now, each instance would hold different ID. You can then use this to differentiate between instance of the Window.


这篇关于打开2 Windows(WPF)与其他数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆