草庐IT

xa-datasource-property

全部标签

c# - ListBox 和 Datasource - 防止第一项被选中

嘿。我有以下代码填充我的列表框UsersListBox.DataSource=GrpList;但是,在框被填充后,列表中的第一项默认被选中,并且“selectedindexchanged”事件被触发。如何防止在填充列表框后立即选择项目,或者如何防止触发事件?谢谢 最佳答案 为了防止事件触发,这里有两个我过去使用过的选项:在设置数据源时取消注册事件处理程序。UsersListBox.SelectedIndexChanged-=UsersListBox_SelectedIndexChanged;UsersListBox.DataSour

c# - 公约问题: When do you use a Getter/Setter function rather than using a Property

令我印象深刻的是,在尝试操作类中的字段时应该使用C#中的属性。但是当涉及到复杂的计算或数据库时,我们应该使用getter/setter。这是正确的吗?什么时候对属性使用s/getter? 最佳答案 .NET设计指南在Propertiesvs.Methods中提供了这个问题的一些答案。部分。基本上,属性与字段具有相同的语义。你不应该让一个属性抛出异常,属性不应该有副作用,顺序不重要,属性应该相对快速地返回。如果这些事情中的任何一个可能发生,最好使用一种方法。该准则还建议使用返回数组的方法。在决定是使用属性还是方法时,如果我将其视为字段

c# - 如何将 DataSource 转换为 List<T>?

我有以下在DataGridView上加载产品的方法privatevoidLoadProducts(Listproducts){Source.DataSource=products;//SourceisBindingSourceProductsDataGrid.DataSource=Source;}现在我正试图将它们还给我以保存它们,如下所示。privatevoidSaveAll(){Repositoryrepository=Repository.Instance;Listproducts=(List)Source.DataSource;Console.WriteLine("Estees

c# - 属性(property)(没有额外处理)与公共(public)领域

这个问题在这里已经有了答案:Whatisthedifferencebetweenafieldandaproperty?(33个答案)关闭3年前。每当有关于属性可信度的问题时,我发现大部分讨论都是围绕函数/方法与属性展开的。但我也想知道令人信服的原因,即直接使用具有关联私有(private)字段的属性与公共(public)字段本身,以防最常见的获取/设置行为没有其他处理,我的意思是这样publicstringCustomerName;对比privatestringcustomerName;publicstringCustomerName{get{returncustomerName;}s

c# - 流利的 NHibernate "Could not resolve property"

我已经阅读了很多关于相同错误的问题,但没有一个与我的确切问题相匹配。我正在尝试使用FluentNHibernate访问一个对象的属性,该对象本身是根对象的一部分。一些答案说我需要使用投影,其他人说我需要使用连接,我认为它应该通过延迟加载来工作。这是我的两个类以及Fluent映射:美术课publicclassArtist{publicvirtualintId{get;set;}publicvirtualstringName{get;set;}publicvirtualIListAlbums{get;set;}publicvirtualstringMusicBrainzId{get;set

C# WPF 附加属性 - 错误 : "The property does not exist in XML namespace"

我需要为现有的WPF控件(组框、文本框、复选框等)创建一个新属性,该属性将存储其访问级别,因此我找到了附加属性。我以这个网站为例http://dotnetbyexample.blogspot.com.br/2010/05/attached-dependency-properties-for.html一切都很好,但是当我尝试在某些控件上使用它时出现以下错误...Error1Theproperty'DependencyPropertiesHoster.AcessLevel'doesnotexistinXMLnamespace'clr-namespace:ImageGUI.App_Code;

c# - 将DataSource设置为Datagridview后添加一行

我有很多与数据网格的数据源绑定(bind)相关的问题。我有一个DatagridView,我正在从列表中设置DataSourceListli=newList();MyClassO=newMyClass();O.Name="Aden";O.LastName="B";O.Id=12;li.Add(O);O=newMyClass();O.Name="Li";O.LastName="S";O.Id=22;li.Add(O);Mydgv.DataSource=li;MyClass在哪里publicClassMyClass{publicstringName{get;set;}publicstring

c# - Properties.Settings.Default.Save(); ->那个文件在哪里

我有一个使用“设置”的应用。要保存我使用的设置:Properties.Settings.Default.Save();阅读我使用的:Properties.Settings.Default.MyCustomSetting;在我的应用程序文件夹中,我只有exe文件。没有配置文件。我的应用程序运行良好,可以读写设置。如果该文件不在应用程序文件夹中,该文件位于何处? 最佳答案 在我的WindowsXP机器上,设置保存在C:\DocumentsandSettings\\ApplicationData\下某处名为user.config的文件中。

c# - EF4 代码优先 : how to add a relationship without adding a navigation property

我应该如何在不使用任何导航属性的情况下使用CodeFirst来定义关系?之前,我通过在关系的两端使用导航属性来定义一对多和多对多。并在数据库中创建适当的关系。这是类外观的精简版本(为简单起见,我已将多对多关系转换为一对多)。publicclassUser{publicstringUserId{get;set;}publicstringPasswordHash{get;set;}publicboolIsDisabled{get;set;}publicDateTimeAccessExpiryDate{get;set;}publicboolMustChangePassword{get;set

c# - 有没有理由拥有没有 setter/getter 的属性(property)?

我的经理问我使用带有setter而没有getter的属性是否是好的做法。publicclassPropertyWrapper{privateMyClass_field;publicMyClassProperty{set{_field=value;}}publicstringFirstProperty{get{return_field.FirstProperty;}}publicstringSecondProperty{get{return_field.SecondProperty;}}}他将使用其他属性来公开私有(private)字段中的属性,由该setter设置。我的建议是只使用私有