草庐IT

collection_items

全部标签

c# - WPF 数据网格 : DataGridComboxBox ItemsSource Binding to a Collection of Collections

情况:我在XAML中创建了一个DataGrid,并且ItemsSource绑定(bind)到包含属性的特定类的ObservableCollection。然后在C#中,我创建了一个DataGridTextColumn和一个DataGridComboBoxColumn,并将它们绑定(bind)到ObservableCollection中对象的属性。我可以将DataGridComboBoxColumn绑定(bind)到一个简单的Collection,但我想要做的是将它绑定(bind)到一个字符串集合的集合,这样对于每一行,DataGrid中的ComboBox都有一个不同的字符串集合。我没有这

c# - Children.Add(item) 值不在预期范围内

我正在开发Silverlight3应用程序,当我尝试将对象添加到Canvas时遇到这个非常奇怪的错误。我的代码如下:for(inti=0;i我第一次使用它时,它按预期工作。但是,当我在单击使用此代码创建的Person对象后点击x_LayoutRoot.Children.Add(child)时,我收到一个ArgumentException,告诉我“值不在预期范围内。”但是,当我在将child添加到x_LayoutRoot.Children之前添加以下代码时,问题就消失了。child.SetValue(Canvas.NameProperty,"child"+objCount++);为什么会

c# - "Items collection cannot be modified when the DataSource property is set."

很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visitthehelpcenter.关闭11年前。通过表单将文件添加到txt文件的程序有这个问题,但这个问题没有说明Fstream的任何内容,所以我认为它不必处理它,但我不确定是什么这个问题的意思是。lstEmployees.Items.Add("Norecordsfound.");

c# - MVC 错误 : The model item passed into the dictionary is null

我只是想建立一个View,但我收到以下错误:System.InvalidOperationException:Themodelitempassedintothedictionaryisnull,butthisdictionaryrequiresanon-nullmodelitemoftype'System.DateTime现在,我知道为什么会出现这种情况,数据库中的特定字段是空值,但它应该是空值,因为这是稍后编辑的内容。这是我的代码:ActionpublicActionResultView(Int64?Id){ModelContainerctn=newModelContainer();

C# GC.Collect 如果对象是使用实例构造函数初始值设定项构造的,则不会销毁该对象

这个问题在这里已经有了答案:关闭9年前。PossibleDuplicate:ResurrectiondifferenceinusingObjectInitializer我很难理解垃圾收集器在C#中的工作原理(我使用的是2012,所以是c#4.5)。这是我的示例代码:publicclassA{publicintc;publicA(){}publicA(intpC){c=pC;}}publicstaticvoidMain(){//Test1vara=newA{c=199};varaRef=newWeakReference(a);a=null;Console.WriteLine(aRef.I

c# - System.Collections.Generic.List<T> 需要 '1' 类型参数

我在以下代码中遇到此错误:string[]colors={"green","brown","blue","red"};varlist=newList(colors);IEnumerablequery=list.Where(c=>c.length==3);list.Remove("red");Console.WriteLine(query.Count());此外,Count()似乎不再被允许。它被弃用了吗? 最佳答案 您正在尝试创建一个List你应该告诉编译器varlist=newList(colors);没有List,有一个名为Li

c# - 奇怪的 "Collection was modified after the enumerator was instantiated"异常

也许有人可以为我指出正确的方向,因为我对此一头雾水。我有一个函数可以简单地打印出类的LinkedList:LinkedListcomponents=newLinkedList();...privatevoidPrintComponentList(){Console.WriteLine("---ComponentList:"+components.Count+"entries---");foreach(Componentcincomponents){Console.WriteLine(c);}Console.WriteLine("------");}Component对象实际上有一个自定

c# - 避免 InvalidOperationException : Collection was modified? 的最佳实践

我经常需要这样的东西:foreach(Linelineinlines){if(line.FullfilsCertainConditions()){lines.Remove(line)}}这不起作用,因为我总是得到一个InvalidOperationException,因为Enumerator在循环期间被更改了。所以我将所有此类循环更改为以下内容:Listremove=newList();foreach(Linelineinlines){if(line.FullfilsCertainConditions()){remove.Add(line)}}foreach(Linelineinrem

c# - 根据 item.key 获取字典项的索引

如何根据元素键找到字典元素的索引?我正在使用以下代码来浏览字典:foreach(varentryinfreq){varword=entry.Key;varwordFreq=entry.Value;inttermIndex=??????;}有人能帮忙吗? 最佳答案 Dictionary中没有索引的概念。您不能依赖Dictionary中项目的任何顺序。OrderedDictionary可能是替代方案。varfreq=newOrderedDictionary();//...foreach(varentryinfreq){varword=e

c# - 递归 LINQ 查询 : select item and all children with subchildren

有没有什么方法可以编写一个LINQ(或过程式)查询,它可以通过一个查询选择一个项目和所有子项?我有实体:publicclassComment{publicintId{get;set;}publicintParentId{get;set;}publicintText{get;set;}}我有一个ID,所以我想选择带有ID的Comment及其所有子项和子项。示例:1-2--3-4-5--623如果ID==1那么我想要1,2,3,4,5,6的列表。 最佳答案 publicclassComment{publicintId{get;set;}