亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

C#對(duì)XtraGrid控件實(shí)現(xiàn)主從表關(guān)系綁定

 更新時(shí)間:2022年06月14日 15:58:08   作者:springsnow  
這篇文章介紹了C#對(duì)XtraGrid控件實(shí)現(xiàn)主從表關(guān)系綁定的方法,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

1、準(zhǔn)備源數(shù)據(jù)。

/// <summary>
/// 記錄基礎(chǔ)信息
/// </summary>
public class DetailInfo
{
    public DetailInfo()
    {
        this.ID = Guid.NewGuid().ToString();
    }

    /// <summary>
    /// ID標(biāo)識(shí)
    /// </summary>
    public string ID { get; set; }

    /// <summary>
    /// 名稱(chēng)
    /// </summary>
    public string Name { get; set; }

    /// <summary>
    /// 描述信息
    /// </summary>
    public string Description { get; set; }
}

/// <summary>
/// 二級(jí)層次的列表
/// </summary>
public class Detail2Result : DetailInfo
{
    public List<DetailInfo> Detail2List { get; set; }
}

2、綁定數(shù)據(jù)源

/// <summary>
/// 綁定數(shù)據(jù)源
/// </summary>
private void BindData()
{
    //創(chuàng)建測(cè)試數(shù)據(jù)
    var result1 = new Detail2Result()
    {
        Name = "測(cè)試1",
        Description = "描述內(nèi)容",
        Detail2List = new List<DetailInfo>()
        {
            new DetailInfo()
            {
                Name = "111測(cè)試",
                Description = "111描述內(nèi)容"
            },
            new DetailInfo()
            {
                Name = "222測(cè)試",
                Description = "222描述內(nèi)容"
            },
            new DetailInfo()
            {
                Name = "333測(cè)試",
                Description = "333描述內(nèi)容"
            }
        }
    };

    var result2 = new Detail2Result()
    {
        Name = "測(cè)試2",
        Description = "描述內(nèi)容",
        Detail2List = new List<DetailInfo>()
        {
            new DetailInfo()
            {
                Name = "111測(cè)試",
                Description = "111描述內(nèi)容"
            },
            new DetailInfo()
            {
                Name = "222測(cè)試",
                Description = "222描述內(nèi)容"
            },
            new DetailInfo()
            {
                Name = "333測(cè)試",
                Description = "333描述內(nèi)容"
            }
        }
    };

    //構(gòu)造一個(gè)記錄的集合
    var list = new List<Detail2Result>() { result1, result2 };

    //綁定數(shù)據(jù)源
    this.gridControl.DataSource = list;
}

3、DevExpress的GridControl控件的設(shè)置

在主視圖下添加一層視圖為gridView2,并修改當(dāng)前視圖的 Change LeveName 為Detail2List (如果不修改結(jié)果是數(shù)據(jù)綁定失敗)

設(shè)置gridView2屬性中的ViewCaption 屬性。

4、效果

5、子表格獲取行數(shù)據(jù)

DevExpress.XtraGrid.Views.Grid.GridView currentView = (DevExpress.XtraGrid.Views.Grid.GridView)this.gridControl.FocusedView;
DetailInfo focusRow = currentView.GetFocusedRow() as DetailInfo; //用在事件中:currentView.GetRow(e.RowHandle) as DetailInfo;
XtraMessageBox.Show(focusRow.Name);

到此這篇關(guān)于C#對(duì)XtraGrid控件實(shí)現(xiàn)主從表關(guān)系綁定的文章就介紹到這了。希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論