简体   繁体   English

C#如何知道要基于与datagridview一起使用的接口的类需要重新实现哪些方法?

[英]C# How do I know what methods need to be reimplemented for a class based on a interface that is to be used with a datagridview?

I would like to make a class based on interfaces such as a list (or binding list) to store data that will be used with a datagridview 我想基于诸如列表(或绑定列表)之类的接口创建一个类,以存储将与datagridview一起使用的数据

My question is when designing such code how can I easily find out what methods I need to implement to provide the required functionality and which interfaces need to be inherited (eg ICloneable, IComparible, IList, , IEnumerator, etc, etc)? 我的问题是,在设计此类代码时,如何才能轻松找出需要实现哪些方法以提供所需的功能以及需要继承哪些接口(例如,ICloneable,IComparible,IList 、、 IEnumerator等)?

or another why of putting it, when inheriting a interface how can I easy find out which methods need to be custom written? 或另一个为什么要放置它,在继承接口时如何轻松找出需要自定义编写的方法? does visual studio offer tools that help? Visual Studio是否提供可以帮助您的工具? obviously many methods will use generics and may not necessarily need rewriting. 显然,许多方法将使用泛型,并且不一定需要重写。

Also how can I easily find out what methods (and there interfaces) a datagridview will call from its data source? 另外,如何才能轻松找出datagridview将从其数据源调用的方法(以及存在的接口)?

I have used a datagridview as an example, however, would be grateful of generic solutions that I can use in other areas in the future and learn from. 我以datagridview为例,但是,我将感激将来可以在其他领域中使用并学习的通用解决方案。

At the moment I am a bit overwhelmed when it comes to where to start and finding this information. 目前,关于从哪里开始并查找此信息,我有点不知所措。 Surely visual studio (express) has some functionality that can help? Visual Studio(Express)肯定有一些功能可以帮助您吗?

I am not sure I understand your question... 我不确定我是否理解您的问题...
If a class implements an interface, it must implement ALL members defined by the interface. 如果一个类实现一个接口,则它必须实现该接口定义的ALL成员。

You can also use .net Reflector to view the microsoft control asemblies. 您也可以使用.net Reflector查看Microsoft控件程序集。 It will show you all base classes and interfaces controls implement. 它将向您显示所有基类和接口控件的实现。 Failing that MSDN usually has good documentation on all its controls. 如果没有,MSDN通常在其所有控件上都有好的文档。

DataGridView details can be found at: http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.aspx 可以在以下位置找到DataGridView的详细信息: http : //msdn.microsoft.com/zh-cn/library/system.windows.forms.datagridview.aspx

The most important thing for a DataGridView is to provide a correct DataSource. 对于DataGridView,最重要的事情是提供正确的DataSource。 Have a look into the documentation: 看一下文档:

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.datasource.aspx http://msdn.microsoft.com/zh-CN/library/system.windows.forms.datagridview.datasource.aspx

As written there, a DataSource must implement just one of the following interfaces: 如此处所述,DataSource必须仅实现以下接口之一:

  • IList 清单
  • IListSource IListSource
  • IBindingList 绑定列表
  • IBindingListView IBindingListView

Using Visual Studio, as soon as you type 键入后立即使用Visual Studio

  public class MyClass : IBindingList

you will be offered a "smart tag", where Visual Studio suggests to make an empty implementation for all of your interface methods automatically. 系统会为您提供一个“智能标记”,Visual Studio建议您为所有接口方法自动实现一个空的实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我如何知道 C# Unity 中 AndroidJavaObject 类中的方法 - How do I know the Methods in AndroidJavaObject class in C# Unity 为什么子类需要实现父接口来隐藏C#中的父类方法之一? - Why do a child class need to implement a parents interface to hide one of that parents methods in C#? 如何从C#类方法中找到调用哪些方法 - 而不是在运行时 - How do I find what methods are called from a C# class method - NOT at run time C#DataGridView添加一行 - 验证时,如何知道该行是新的还是尚未提交? - C# DataGridView Adding a Row - When validating, how do I know the row is new and not yet committed? 单元测试模拟控制器,C#我需要模拟HTTPContext吗? 我要嘲笑什么方法? - Unit Test Mock Controller, C# Do I need to Mock HTTPContext? What methods do I mock? Xamarin C#如何为AppDelegate添加接口或类? - Xamarin C# how do i add interface or class to AppDelegate? 我如何转换列表 <Interface> 列表 <Class> 在c#中 - How do i convert a List<Interface> to List<Class> in c# 如何使用c#扩展方法扩展类? - How do I extend a class with c# extension methods? 如何使用 C# 命名空间附带的 class 的方法 - How do I use the methods of a class that comes with a C# namespace 如何在C#中的方法中使用类名作为参数? - How do I use class names as parameters in methods in C#?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM