第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何利用用戶從 DataContext 添加到列表中的信息?

如何利用用戶從 DataContext 添加到列表中的信息?

C#
慕的地6264312 2022-11-13 13:43:20
使用來自主網(wǎng)格的數(shù)據(jù)上下文,我試圖使用從用戶那里收集的信息并將其存儲(chǔ)在一個(gè)列表中,然后使用該列表并能夠使用 LINQ 獲取信息。ColDiv._inventaire.Add(inventaire);Coldiv 是我的 cs 文件之一,_inventaire 是列表,inventaire 是數(shù)據(jù)上下文中的數(shù)據(jù)。ColDiv 的代碼在我的班級之一中:class CollectionsDiverses{    public List<Client> _client = new List<Client>();    public List<Inventaire> _inventaire = new List<Inventaire>();    public List<Vente> _VenteArticle = new List<Vente>();這是將網(wǎng)格中的數(shù)據(jù)上下文放入屬性和列表中的代碼。(列表如下)Inventaire inventaire = null;frmArticle frmArticle = new frmArticlebool? bReturn = frmArticle.ShowDialog();if (bReturn == true){    inventaire = (Inventaire)frmArticle.grdMain.DataContext;    inventaire.Créé = DateTime.Now.ToString();    ColDiv._inventaire.Add(inventaire);    dgInventaire.Items.Refresh()}現(xiàn)在從邏輯上講,它被存儲(chǔ)了?,F(xiàn)在,從另一個(gè)來自帶有 TextChanged 事件的 TextBox 捕獲(例如)客戶端的 ID:private void TxtNoArticle_TextChanged(object sender, TextChangedEventArgs e){    try    {        _venteEdition.NoArticle = Int32.Parse(txtNoArticle.Text);         _venteEdition.ArticleComplet = ArticleCompletToString(_venteEdition.NoArticle);        lblArticleComplet.Content = _venteEdition.ArticleComplet;    }    catch (Exception){}然后從一個(gè)方法繼續(xù)使用 LINQ 來查找具有用戶輸入的 ID 的客戶端:public string ArticleCompletToString(int iNombre){    string sArticle = "";    var req = from art in ColDiv._inventaire              where art.No == iNombre // art.No is the ID the user wants and iNombre is the ID the user entered in the TextBox              select new              {                  art.Modèle,                  art.Marque              };    foreach (var i in req)    {        sArticle = i.Modèle + " " + i.Marque;    }    return sArticle;它應(yīng)該從列表中準(zhǔn)確返回我想要的信息,但看起來它甚至沒有創(chuàng)建新的 Inventaire。
查看完整描述

1 回答

?
汪汪一只貓

TA貢獻(xiàn)1898條經(jīng)驗(yàn) 獲得超8個(gè)贊

好的,找到了問題。我以三種不同的形式對 ColDiv 進(jìn)行了三次初始化,因此您唯一要做的就是在 main 中進(jìn)行初始化,并將其設(shè)為公開和靜態(tài)。在另一種形式中,只需按以下方式初始化它:


public partial class frmVentes : Window

{

    private CollectionsDiverses _ColDiv;


    public frmVentes()

    {

        InitializeComponent();

        this._ColDiv = MainWindow.ColDiv;

    }


//...

在您的主代碼中,它看起來像這樣:


public partial class MainWindow : Window

{

    public static CollectionDiverses ColDiv = new CollectionsDiverses();



    public MainWindow()

    {

        InitializeComponent();

    }

//...

現(xiàn)在,在您的 CollectionsDiverses 類中,您想像這樣將其更改為 public


public class CollectionsDiverses

{

//...

您必須為您的列表創(chuàng)建一個(gè)內(nèi)部屬性:


private List<Client> client = new List<Client>();

private List<Inventaire> inventaire = new List<Inventaire>();

//...


internal List<Client> Client { get => client; set => client = value; }

internal List<Vente> VenteArticle { get => venteArticle; set => venteArticle = value; }

//...

而已 !現(xiàn)在已經(jīng)修復(fù)了,我可以使用不同表單之間的信息了!


查看完整回答
反對 回復(fù) 2022-11-13
  • 1 回答
  • 0 關(guān)注
  • 104 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號