大家好,先向大家鞠躬了问题如下:我数据库里面都是用户存的快餐清单,例如,里面存着,鸡肉,猪肉,红烧肉啊啥的清单,然后我要在界面把这些数据库里面的东西全部导出来 如同一个BUTTON一样的外观,当用户一点这个特定的BUTTON,例如红烧肉,那么我知道用户是在点了红烧肉,,然后这个红烧肉被我存在另外一个数据库里面,呆会打印出来,, 流程如下:从DB中获得各项菜名——》各项菜名已按钮形式显示在窗口上,给用户点击--》获得点击的菜名,然后保存到另外一个DB中--》打印 ,现在问题是当我用户点在红烧肉上,怎么知道这么动态生成的红烧肉被点到了吗???
感谢大家了,,,敬礼

解决方案 »

  1.   

    另外我还有一个是XML..很简单结构,我怎么能判断LISTBOX(或者LISTVIEW) 里面不同的XML NAME被点几了呢???
    例如如下代码..被我绑在LISTBOX(或者LISTVIEW) 里面然后产生了4个BUTTON,我怎么能判断第一BUTTON被点几是USER MGMT? 依此类推????希望高人能给我提供理解....
    <Catalog>
    <Products>
    <Product>
    <Name>User Mgmt</Name>
    <Image>Images\product01.png</Image>
    <Description>High resistent polymers and aluminum extracts that will protect your widget for life. Fire, Snow, Water or Dust... This guy takes it all.</Description>
    <Price>$89.00</Price>
    </Product>
    <Product>
    <Name>Product Mgmt</Name>
    <Image>Images\product02.png</Image>
    <Description>Add some high quality audio to your video experience. With these comfortable headphones you'll feel like sound comes out of your brain.</Description>
    <Price>$19.90</Price>
    </Product>
    <Product>
    <Name>Customer Mgmt</Name>
    <Image>Images\product03.png</Image>
    <Description>Get connected to local wireless networks and download streaming media directly to your VPR-1000</Description>
    <Price>$38.45</Price>
    </Product>
    <Product>
    <Name>Business Report</Name>
    <Image>Images\product04.png</Image>
    <Description>If you are about to travel then you need extra storage space.  With this 2TB drive you'll finally be able to take thousands of hours of entertainment with you.</Description>
    <Price>$75.90</Price>
    </Product> </Products>

    </Catalog>
      

  2.   


    大哥,我意思是说这些BUTTON是被自动生成出来的,它们没有ID的噢我觉得,,,怎么判断被点了???
      

  3.   

    用事件,所有的BUTTON.CLICK都会触发。
    既然button上能看到菜名,肯定是某个属性被赋值为菜名了呗(例如是caption属性),取出来
    类似的例子可以参考的简单计算器应用程序的代码,很多地方都有下
      

  4.   

    是不是这意思    //菜结构体
        public struct Product
        {
            private string _name;
            private string _image;
            private string _description;
            private decimal _price;        public Product(string name, string image, string description, decimal price)
            {
                this._name = name;
                this._image = image;
                this._description = description;
                this._price = price;
            }        public string Name
            {
                get { return _name; }
                set { _name = value; }
            }        public string Image
            {
                get { return _image; }
                set { _image = value; }
            }        public string Description
            {
                get { return _description; }
                set { _description = value; }
            }        public string Price
            {
                get { return _price; }
                set { _price = value; }
            }
        }    public class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }        //加载数据
            private void LoadData(object sender, EventArgs e)
            {
                //按DB自动生成按钮
                Button btn = new Button();
                //菜信息存储
                btn.Text = "菜名";
                btn.Tag = new Product("菜名", "图片", "描述", 10);
                //绑定事件
                btn.Click+=new EventHandler(btn_Click);
            }        //菜按钮点击
            private void button_Click(object sender, EventArgs e)
            {
                Button currentBtn = sender as Button;
                Product myP = (Product)currentBtn.Tag;            //菜名
                MessageBox.Show(myP.Name);
                //...其它(略)
                //拿去保存
            }
        }
      

  5.   

    感谢楼上的帮我出主义,我早上来又仔细看了一下,,,我现在C# 的代码如下,,,我觉得您这个我还是看得不明白,我把我的给贴出来,如果有人可以给点建设性意见改改就太好了...另外我用的是WPF, 不是WINDOWS FORM,,, 但是没什么区别的...
    namespace DBconnection
    {    public struct ProductFoods
        {
            private string _id;
            private string _name;
            private decimal _price;        public ProductFoods(string id, string name, decimal price)
            {
                this._id = id;
                this._name = name;
                this._price = price;
            }        public string id
            {
                get { return _id; }
                set { _id = value; }
            }        public string name
            {
                get { return _name; }
                set { _name = value; }
            }        public decimal Price
            {
                get { return _price; }
                set { _price = value; }
            }
        }    public partial class ProductInitialize : Window
        {
            public ProductInitialize()
            {
               InitializeComponent();
            }    }      public class Products
        {
            private SqlConnection sqlConn = new SqlConnection();
            string conn = @"server=DEVTAO\SQLEXPRESS;" + "database=testdb;" + "Integrated Security=SSPI;" + "Connection Timeout=100";        public SqlConnection openConnection(string connectionString)
            {
                sqlConn.ConnectionString = connectionString;
                sqlConn.Open();
                return sqlConn;
            }        public void closeConnection()
            {
                sqlConn.Close();
            }        public ArrayList GetProducts()
            {
                ArrayList myProducts = new ArrayList();
                sqlConn = new SqlConnection(conn);
                SqlCommand cmd = new SqlCommand("GetProducts", sqlConn);
                cmd.CommandType = CommandType.StoredProcedure;
                SqlDataAdapter adapter = new SqlDataAdapter(cmd);
                DataSet ds = new DataSet();
                adapter.Fill(ds, "Products");            foreach (DataTable dt in ds.Tables)
                {
                    for (int curRow = 0; curRow < dt.Rows.Count; curRow++)
                    {
                        myProducts.Add(dt.Rows[curRow][1].ToString());
                    }
                }
                return myProducts;
            }    }
    } 我数据库结构是 如下:db_id   int   (primary key ,)
    products_id   varchar(MAX)
    Products      varchar(MAX)
    Price         float
    里面内容就是乱七八糟的假设数据了,,,
    希望各位大虾给点思路,,,新手求救嘛....哎
      

  6.   

    其实我的问题我想我简单的说一下就是,,你知道LISTBOX这个控件是吧...它挺讨厌是,当那些LISTITEM在它里面出现的时候你只能点这些ITEM背景才能选种,.例如我是让这些LISTITEM以BUTTON的形式表达出来..但是这些BUTTON是浮在LISTITEM上面的,我点BUTTON没办法选择中背景,这个很让我不爽啊,,,这些BUTTON又是一个然后动态产生出来的,我就这个地方被挡住了...