1

I would like to display the data which I get from List when the result of my List is = to 1. I need to get the FileName, Title and HotspotID.

Can somebody help me with it? The part that I need help is at the end part of my code.

here is the code:

    private void PerformSheetLink(String hotspotID, Int32 fileRec)
    {
        string nomenclature = dataLayer.GetNomenclature(fileRec, hotspotID);
        string pattern = @"\((?<ProjectRec>\d+(?:_)?\d*?)*\,(?<FileName>[^,]*)\,(?<HotspotID>[^)]*)\)";
        Regex regex = new Regex(pattern, RegexOptions.Compiled);
        Match m = regex.Match(nomenclature);

        //Multiple numenclature exist           
        if (regex.Matches(nomenclature).Count > 1)
        {
            List<P2Trace> linkList = new List<P2Trace>();
            string fileName, hotspot, title;                
            MatchCollection mc = regex.Matches(nomenclature);
            foreach (Match match in mc)
            {
                //This match has a Single Project
                GroupCollection gc = match.Groups;
                if (gc["ProjectRec"].Captures.Count == 1)
                {
                    if ((int)cbModel.SelectedValue == Int32.Parse(gc["ProjectRec"].Value))
                    {
                        fileName = String.Format("{0}.cgm", gc["FileName"].Value);
                        title = dataLayer.GetSheetTitle(fileName);
                        hotspot = FixHotspotID(gc["HotspotID"].Value);
                        linkList.Add(new P2Trace { FileName = fileName, HotspotID = hotspot, Title = title });
                    }
                }
                else
                {
                    //This match has Multiple Projects 
                    List<Int32> pRecs = GetProjectRecsInList(gc["ProjectRec"].Captures);
                    if (pRecs.Contains((int)cbModel.SelectedValue))
                    {
                        foreach (Int32 projectRecNo in pRecs)
                        {
                            if (projectRecNo == (int)cbModel.SelectedValue)
                            {
                                fileName = String.Format("{0}.cgm", gc["FileName"].Value);
                                title = dataLayer.GetSheetTitle(fileName);
                                hotspot = FixHotspotID(gc["HotspotID"].Value);
                                linkList.Add(new P2Trace { FileName = fileName, HotspotID = hotspot, Title = title });
                            }
                        }
                    }
                }
            }
            //Link found and collected, perform jump
            if (linkList.Count == 1)
            {
               p2Trace.FileName = linkList. ?????
               p2Trace.Title = linkList. ??????
               p2Trace.HotspotID= linkList. ??????
               jumpTo(p2Trace.FileName, p2Trace.Titel, p2Trace.HotspotID);

            }
2
  • Is it your intent to only call the jumpTo if you find exactly one match? What should happen if you found two matches? Commented Jan 23, 2014 at 19:43
  • I already took care of that part, i just didn't post the code Commented Jan 23, 2014 at 19:47

2 Answers 2

1
p2Trace.FileName = linkList[0].FileName;
p2Trace.Title = linkList[0].Title;
p2Trace.HotspotID = linkList[0].HotspotID;
Sign up to request clarification or add additional context in comments.

Comments

0

Try this...

    if (linkList.Count == 1)
    {
var firstItem = linkList[0];
       p2Trace.FileName = firstItem.FileName;
       p2Trace.Title = firstItem.Title;
       p2Trace.HotspotID= firstItem.HostspotID;
       jumpTo(p2Trace.FileName, p2Trace.Titel, p2Trace.HotspotID);

    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.