<tfoot id='udmPX'></tfoot>
  • <small id='udmPX'></small><noframes id='udmPX'>

    1. <legend id='udmPX'><style id='udmPX'><dir id='udmPX'><q id='udmPX'></q></dir></style></legend>
    2. <i id='udmPX'><tr id='udmPX'><dt id='udmPX'><q id='udmPX'><span id='udmPX'><b id='udmPX'><form id='udmPX'><ins id='udmPX'></ins><ul id='udmPX'></ul><sub id='udmPX'></sub></form><legend id='udmPX'></legend><bdo id='udmPX'><pre id='udmPX'><center id='udmPX'></center></pre></bdo></b><th id='udmPX'></th></span></q></dt></tr></i><div id='udmPX'><tfoot id='udmPX'></tfoot><dl id='udmPX'><fieldset id='udmPX'></fieldset></dl></div>
        <bdo id='udmPX'></bdo><ul id='udmPX'></ul>

        (c# + windows forms) 将项目添加到不同类的listBox

        (c# + windows forms) Adding items to listBox in different class((c# + windows forms) 将项目添加到不同类的listBox)
          <tfoot id='c3L8G'></tfoot>

              <bdo id='c3L8G'></bdo><ul id='c3L8G'></ul>
                <tbody id='c3L8G'></tbody>

                  <legend id='c3L8G'><style id='c3L8G'><dir id='c3L8G'><q id='c3L8G'></q></dir></style></legend>

                  <small id='c3L8G'></small><noframes id='c3L8G'>

                  <i id='c3L8G'><tr id='c3L8G'><dt id='c3L8G'><q id='c3L8G'><span id='c3L8G'><b id='c3L8G'><form id='c3L8G'><ins id='c3L8G'></ins><ul id='c3L8G'></ul><sub id='c3L8G'></sub></form><legend id='c3L8G'></legend><bdo id='c3L8G'><pre id='c3L8G'><center id='c3L8G'></center></pre></bdo></b><th id='c3L8G'></th></span></q></dt></tr></i><div id='c3L8G'><tfoot id='c3L8G'></tfoot><dl id='c3L8G'><fieldset id='c3L8G'></fieldset></dl></div>
                  本文介绍了(c# + windows forms) 将项目添加到不同类的listBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有两个类(表单),我希望在单击时将 class2 中的一个项目添加到 class1 中的 listBox接受"按钮.

                  I have two classes(forms), and I would like an item from class2 to be added to listBox in class1 when I click "Accept" button.

                  我尝试了以下代码,但列表框没有任何变化:

                  I tried with the following code, but nothing changes in the listBox:

                  private void button1_Click(object sender, EventArgs e)
                  {
                      CarRental i = new CarRental();
                      string id = idRental.Text.ToString();
                  
                      i.listBox1.Items.Add(id);
                      i.listBox1.Update();
                      this.Close();
                  }
                  

                  我在哪里犯错了?

                  推荐答案

                  Form2 上声明 RentalId 属性.在 CarRental 表单(您的第一个表单)中执行以下操作:

                  Declare RentalId property on Form2. And at CarRental form (your first form) do following:

                  using(Form2 form2 = new Form2())
                  {
                      if (fomr2.ShowDialog() != DialogResult.OK)
                          return;
                  
                      listBox.Items.Add(form2.RentalId);
                  }
                  

                  以这种方式实现 Fomr2.RentalId 属性:

                  Implement Fomr2.RentalId property this way:

                  public string RentalId
                  {
                     get { return idRental.Text; } // you don't need ToString() call
                  }
                  

                  然后选择接受"按钮并将其 DialogResult 属性设置为 OK.因此,单击该按钮将关闭您的对话框并返回 DialogResult.OK.

                  Then select your "Accept" button and set its DialogResult property to OK. Thus clicking on that button will close your dialog form and return DialogResult.OK.

                  这篇关于(c# + windows forms) 将项目添加到不同类的listBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Populate ListBox with a IEnumrable on another thread (winforms)(在另一个线程(winforms)上使用 IEnumrable 填充 ListBox)
                  listbox selected item give me quot; System.Data.DataRowViewquot; , C# winforms(列表框选择的项目给我quot;System.Data.DataRowView, C# Winforms)
                  Cannot remove items from ListBox(无法从列表框中删除项目)
                  Preventing ListBox scrolling to top when updated(更新时防止列表框滚动到顶部)
                  Drag and drop from list to canvas on windows phone with MVVM(使用 MVVM 在 Windows 手机上从列表拖放到画布)
                  Deselection on a WPF listbox with extended selection mode(具有扩展选择模式的 WPF 列表框上的取消选择)

                      • <tfoot id='nfUMj'></tfoot>
                            <bdo id='nfUMj'></bdo><ul id='nfUMj'></ul>

                          • <small id='nfUMj'></small><noframes id='nfUMj'>

                          • <legend id='nfUMj'><style id='nfUMj'><dir id='nfUMj'><q id='nfUMj'></q></dir></style></legend>
                              <tbody id='nfUMj'></tbody>
                            <i id='nfUMj'><tr id='nfUMj'><dt id='nfUMj'><q id='nfUMj'><span id='nfUMj'><b id='nfUMj'><form id='nfUMj'><ins id='nfUMj'></ins><ul id='nfUMj'></ul><sub id='nfUMj'></sub></form><legend id='nfUMj'></legend><bdo id='nfUMj'><pre id='nfUMj'><center id='nfUMj'></center></pre></bdo></b><th id='nfUMj'></th></span></q></dt></tr></i><div id='nfUMj'><tfoot id='nfUMj'></tfoot><dl id='nfUMj'><fieldset id='nfUMj'></fieldset></dl></div>