我自定义了一个控件 里面一个button 一个datagridview 点击button可以显示数据
现在新建一个winform项目 在窗体把自定义控件拖进去  再在窗体中添加个按钮 要实现点击按钮 可以显示自定义控件当中显示的数据。求解啊 

解决方案 »

  1.   

    什么乱七八糟的,自定义控件发布一个方法,比如 GetData,你调用一下,自定义中就可以去获取数据,如果要访问grid,那可以把grid的modifers属性设置为public,这样就可以直接通过实例yourcontrol.datagridview1来访问量,当然还可以通过属性的getter来获得,方法多得很
      

  2.   

    求什么代码,新建用户控件(usercontrol),上面方式grid啥的
    datagridview 的modifers改为public,然后把自定义控件放到窗体上(可以代码创建),随后就是xxxx.datagridview 访问就是了
      

  3.   


    用户控件using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Drawing;
    using System.Data;
    using System.Text;
    using System.Windows.Forms;namespace WindowsApplication1
    {
        public partial class UserControl1 : UserControl
        {        public DataTable dt=new DataTable();
            public UserControl1()
            {
                InitializeComponent();
            }        private void button1_Click(object sender, EventArgs e)
            {            dataGridView1.DataSource = dt;
            }    }
    }
    winform项目
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;namespace WindowsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();            DataTable datatable = new DataTable();
                datatable.Columns.Add("abc");
                DataRow dr = datatable.NewRow();
                dr["abc"] = "213";
                datatable.Rows.Add(dr);            userControl11.dt = datatable;
            }
        }
    }