如何在datagridview中显示子列表中的项目 [英] How do I show items from sublist in datagridview

查看:99
本文介绍了如何在datagridview中显示子列表中的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,



我的问题是,如何将存储在pD.Operations中的List< string> Operations的字符串显示为子列表一个datagridview?





Hey,

my problem is, how can I show the strings of my "List<string> Operations" stored in "pD.Operations" as sublist on a datagridview ?


<pre>            dataGridViewPDM.DataSource = null;
            dataGridViewPDM.Rows.Clear();
            LblCount.Text = "";1
            //
            List<PdmObjectId> pdmObjects = new List<PdmObjectId>(TopSolidHost.Pdm.GetProjects(true, false));
            ProjectOps_TS ops_TS = new ProjectOps_TS();
            List<PDMparam> list = new List<PDMparam>();
            folder = comboBox1.SelectedItem.ToString();
            for (int i = 1; i < pdmObjects.Count; i++)
            {
                Cursor.Current = Cursors.WaitCursor;
                List<string> AFO = new List<string>();
                if (ops_TS.Read_projekt_with_sub(pdmObjects[i], folder, out artnr, out beschr, out znnr, out AFO))
                {
                    PDMparam pD = new PDMparam();
                    List<PDMparam> vs = new List<PDMparam>();
                    pD.Maschine = folder;
                    pD.Artikelnummer = artnr;
                    pD.Beschreibung = beschr;
                    pD.Zeichnungsnummer = znnr;
                    pD.PdmObjId = pdmObjects[i].Id;
                    pD.Operations = AFO;
                    vs.Add(pD);
                    list.AddRange(vs);
                }
            }
            var list_dgv = new BindingList<PDMparam>(list);
            //dataGrid1.DataSource = list_dgv;
            dataGridViewPDM.DataSource = list_dgv;
            LblCount.Text = list.Count + " Ordner";
            Cursor.Current = Cursors.Default;







<pre>public class PDMparam
    {
        public string Maschine { get; set; }
        public string Artikelnummer { get; set; }
        public string Beschreibung { get; set; }
        public string Zeichnungsnummer { get; set; }
        public string PdmObjId { get; set; }
        public List<string> Operations { get; set; }
    }





我尝试过:



我也尝试过datagrid组件,这样可行,但我得到的不是字符串值,只是列表中字符串的长度< string>



What I have tried:

I have tried also datagrid component, this would work, but I get not the string value, only the lenght of the string in the list<string>

推荐答案

如果我理解你正确,当你说子列表时你需要pD.Operations项目,它是一个List< string>在网格中显示为网格?我不认为你会得到你想要的东西,除非你使用DevExpress的XtraGrid之类的东西,因为他们的网格支持嵌套网格。普通网格(据我所知)不支持这样的东西。

您可以创建PDMparam的新属性并将其命名为OperationsList。做类似的事情

If I understand you right, when you say "sublist" you want the pD.Operations item which is a List<string> to show as a grid within a grid? I don't think you're going to get what you want unless you use something like the XtraGrid from DevExpress because their grid supports nested grids. The normal grid (to my knowledge) doesn't support anything like that.
You could perhaps create a new property of PDMparam and call it OperationsList. Do something like this
public string OperationsList() { 
   get {
      return Operations.join(Envrionment.NEWLINE);
   }
}



我的语法不是100%,从内存输入,我花了三年时间在内存中Swift :)

基本上我的想法是将操作列表作为单个字符串返回,并带有回车符以创建多行列表,该列表应显示在网格单元格中,给出您想要的外观。当然,您必须设置网格列的多行功能,这些功能不可编辑。

我之前使用的另一个选项是两个独立网格之间的连接。当用户使用PDM选择网格中的项目时,您将使用操作列表更新另一个网格的绑定列表。



HTH,Mike


I'm not 100% on the syntax there, typed it from memory and I've spent the last three years in Swift :)
Basically the idea is to return the operations list as a single string with carriage returns to create multi-line list that should show in the grid cell giving the look you want. Of course you'll have to set the multi-line capability of the grid column and these are not editable.
Another option that I've used before is a connection between two separate grids. When the user selects an item in the grid with the PDM, you update a binding list for another grid with the operations list.

HTH, Mike


这篇关于如何在datagridview中显示子列表中的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆