文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>得到DataGrid的某一行列的值

得到DataGrid的某一行列的值

时间:2010-10-18  来源:jasmin

    </Grid>
</UserControl>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SilverlightApplication8
{
    public partial class Page : UserControl
    {
        public Page()
        {
            InitializeComponent();
            dataGrid1.ItemsSource = Customer.GetSampleCustomerList();

        }

        private void dataGrid1_LoadingRow(object sender, DataGridRowEventArgs e)
        {
            Customer bindData = (Customer)e.Row.DataContext;
            Button btn = dataGrid1.Columns[3].GetCellContent(e.Row).FindName("Button1") as Button;
            btn.Content = bindData.UserName;
            btn.Tag = bindData.IndexName + "," + e.Row.GetIndex();
        }

        private void Button1_Click(object sender, RoutedEventArgs e)
        {
            Button b = sender as Button;
            string[] t = b.Tag.ToString().Split(',');
            msg.Text = "你选择的值是:" + t[0] + " 是 DataGrid 的第 " + t[1] + " 行";
        }
    }
    /// <summary>
    /// 数据对象
    /// </summary>
    public class Customer
    {
        public Int32 IndexName { get; set; }
        public String UserName { get; set; }
        public String Address { get; set; }

        public Customer(Int32 indexName, String userName, String address)
        {
            this.IndexName = indexName;
            this.UserName = userName;
            this.Address = address;
        }

        public static List<Customer> GetSampleCustomerList()
        {
            //示例数据
            List<Customer> data = new List<Customer>();
            for (int i = 0; i < 10; i++)
            {
                data.Add(new Customer(i * i, "孟宪会之" + i.ToString(), "地址之" + i.ToString()));
            }
            return data;
        }
    }
}

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载