Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hey,

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


C#
<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;


C#
<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; }
    }


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>
Posted
Updated 2-Jul-18 4:59am
Comments
Krunal Rohit 2-Jul-18 7:02am    
Shouldn't it be this way?-
dataGridViewPDM.DataSource = list_dgv;
dataGridViewPDM.DataBind();


KR
Chris_St 2-Jul-18 7:17am    
No, DataBind is for WebForms, not Winforms.

1 solution

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
C#
public string OperationsList() { 
   get {
      return Operations.join(Envrionment.NEWLINE);
   }
}

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
 
Share this answer
 
Comments
Chris_St 3-Jul-18 1:31am    
Hi Mike,

thank you very much. This solution takes me to the right way... :)

The property should be this way.

public string OperationsList
{
get
{
string joined = string.Join<string>(Environment.NewLine, Operations);
return joined;
}
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900