views:

25

answers:

0

Hello Experts, having issues binding a gridviewcolumn to a string array (that probably sounds mad, but I can't seem to do this in the usual manner as I need to concatenate some xml results into one column cell). When I do the binding it simply hooks into the first string and ignores whatever else is generated into my array. The bit that is going wrong is the binding at the botom. Any help much appreciated!

      private void linksetModDoc_Loaded(object sender, RoutedEventArgs e)
    {
        //MessageBox.Show("Stop Here");
        ListView thisList = sender as ListView;
        XmlLinkedNode thisLinkXML;
        ItemCollection linkedObjectColl = thisList.Items;
        GridViewColumn gvc = targetOfLinkGridViewCol;
        XmlNode thisNode; XmlNodeList targList;
        String[] colCont= new String[linkedObjectColl.Count];
        String[] idCont = new String[linkedObjectColl.Count];
        String[] txtCont = new String[linkedObjectColl.Count];
        String thisValue;

        int i;
        for(i=0;i<colCont.Length;i++) {
            colCont[i] = "";
        }
        //scroll through each object we are about to display add a row for each
        for(i=0;i<linkedObjectColl.Count;i++) {
            //get the xml for this object
            thisLinkXML = (XmlLinkedNode)linkedObjectColl.GetItemAt(i);

            //process the id abs_num
            thisValue = thisLinkXML.SelectSingleNode("abs_num").InnerText;
            if (thisValue != null)
            {
                //add Listviewitem
                //ListBoxItem item = thisList.Items.Add(thisId);
                idCont[i]=thisValue;
                thisNode = thisLinkXML.SelectSingleNode("object_text");
                if (thisNode != null) txtCont[i] = thisNode.InnerText;
                thisNode = thisLinkXML.SelectSingleNode("object_heading");
                if (thisNode != null) txtCont[i] = thisNode.InnerText;


                //process the targets details and display in one cell
                targList = thisLinkXML.SelectNodes("Target");
                foreach (XmlLinkedNode myChildNode in targList)
                {
                    thisValue = myChildNode.SelectSingleNode("abs_num").InnerText;
                    colCont[i] = colCont[i]+ thisValue;
                    thisNode = myChildNode.SelectSingleNode("object_text");
                    if (thisNode != null) colCont[i] = colCont[i] + "\t" + thisNode.InnerText + "\t";
                    thisNode = myChildNode.SelectSingleNode("object_heading");
                    if (thisNode != null) colCont[i] = colCont[i] + "\t" + thisNode.InnerText + "\t";


                }
            }
        }




        //need to bind to a property hence we need the  class to
        //refresh our column only mapping to 
        StringWrapper[] news = new StringWrapper[linkedObjectColl.Count];
        for (i = 0; i < colCont.Length; i++) {
            Console.WriteLine(idCont[i] + "\t" + txtCont[i] +"\t" + colCont[i]);
            news[i] = new StringWrapper();

            news[i].Value = "This is always ignored, but is correct in console"; //colCont[i];
            news[0].Value = "Only EVER GET THIS IN COLUMN";
            Console.WriteLine(news[i].Value);
        }
        Binding binding = new Binding();
        binding.Source = news;
        PropertyPath p = new PropertyPath("Value",news);
        binding.Path = p;

        //Need to display all target elements in the column
        targetOfLinkGridViewCol.DisplayMemberBinding= binding;


    }
    public class StringWrapper
    {
        public String Value { get; set; }
    }