Ejemplo n.º 1
0
        void Events_SelectionChangeEvent()
        {
            /* Make sure that the inner code block is running synchronously */
            lock (_selectionEventHandlerLock)
            {
                System.Console.WriteLine("Selection changed event received.");

                var selection = new Tekla.Structures.Model.UI.ModelObjectSelector()
                                .GetSelectedObjects()
                                .ToAList <Part>();
                if (!selection.Any())
                {
                    return;
                }
                var rawRows = dataGridView1.Rows.OfType <DataGridViewRow>().ToList();

                var assemblies = selection.Select(p => p.GetAssembly());

                var rows = rawRows.AsParallel().Where(r =>
                {
                    dynamic item = r.DataBoundItem;
                    if (item.Id == null)
                    {
                        return(false);
                    }
                    var id = (int)item.Id;
                    return(assemblies.FirstOrDefault(p => p.Identifier.ID == id) != null);
                }).ToList();

                CreateBom(rows);
            }
        }