C# と VB.NET の質問掲示板

ASP.NET、C++/CLI、Java 何でもどうぞ

ログ内検索
  • キーワードを複数指定する場合は 半角スペース で区切ってください。
  • 検索条件は、(AND)=[A かつ B] (OR)=[A または B] となっています。
  • [返信]をクリックすると返信ページへ移動します。
キーワード/ 検索条件 /
検索範囲/ 強調表示/ ON (自動リンクOFF)
結果表示件数/ 記事No検索/ ON
大文字と小文字を区別する

No.87773 の関連記事表示

<< 0 >>
■87773  Re[6]: 別フォームにデータを渡したい
□投稿者/ WebSurfer -(2018/06/29(Fri) 11:26:44)
    No87770 (いまそかり さん) に返信
    
    C# ですがサンプルを書いておきます。Form5 ⇒ Form1, Form6 ⇒ Form2 に読み替えてください。
    
    デザイナで Form5 には Button を、Form6 には ComboBox をドラッグ&ドロップして、必要なイ
    ベントハンドラを生成しただけです。
    
    
    Form5.cs
    
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    
    namespace WindowsFormsApplication2
    {
        public partial class Form5 : Form
        {
            public Form5()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                DataTable table = new DataTable();
                table.Columns.Add(new DataColumn("ID", typeof(Int32)));
                table.Columns.Add(new DataColumn("Name", typeof(string)));
                for (int i = 0; i < 5; i++)
                {
                    DataRow row = table.NewRow();
                    row["ID"] = i;
                    row["Name"] = "Product Name_" + i.ToString();
                    table.Rows.Add(row);
                }
                DataSet df = new DataSet();
                df.Tables.Add(table);
    
                Form6 frm = new Form6(df);
                frm.Show();
            }
        }
    }
    
    
    Form6.cs
    
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    
    namespace WindowsFormsApplication2
    {
        public partial class Form6 : Form
        {
            private DataSet df;
    
            public Form6()
            {
                InitializeComponent();
            }
    
            public Form6(DataSet df)
            {
                InitializeComponent();
                this.df = df;
            }
    
            private void Form6_Load(object sender, EventArgs e)
            {
                comboBox1.DataSource = df.Tables[0];
                comboBox1.DisplayMember = "Name";
                comboBox1.ValueMember = "ID";
            }
        }
    }
記事No.87756 のレス /過去ログ151より / 関連記事表示
削除チェック/



<< 0 >>

パスワード/

- Child Tree -