DataSource和DataMember属性(按代码) [英] DataSource And DataMember Property By Code
问题描述
这是我想做的事情:
对象DataSource_m;
公共对象DataSource
{
获取
{
return DataSource_m;
}
设置
{
DataSource_m =值;
}
}
此属性用于自定义控件.
现在,当我在窗体中添加此控件并转到其属性窗口时,在设计器模式下,将按预期获得A属性作为DataSource.
当我单击数据源属性"以附加数据库时,我没有在该属性中获得添加项目数据源"选项,这通常是在DataGridView控件的数据源属性中得到的.
我应该使用什么属性来获取那个.
屏幕截图:
http://adieu.webs.com/Images/Untitled.bmp
here is what i want to do:
object DataSource_m;
public object DataSource
{
get
{
return DataSource_m;
}
set
{
DataSource_m = value;
}
}
this property is for a Custom Control.
Now When I add this Control in a form and go to its property window I get A property as DataSource as expected, in the designer mode.
when i click the DataSource Property to attach a databse, i dont get the "Add Project DataSource" option in the property, which we usually get in the DataGridView Control''s DataSource Property......
what attributes should i use to get That.
SCREENSHOT:
http://adieu.webs.com/Images/Untitled.bmp
推荐答案
嘿,
在此处 [
Hey there,
There is a walk through here[^] on MSDN that you will find helpful.
The key thing you''re likely missing is adding the attributes required to pick up those properties.
Cheers.
您可以轻松地做到这一点:
you can simply do this:
using System.ComponentModel;
//more using statements
public class YourClass:SomeControl
{
object DataSource_m;
[AttributeProvider(typeof(IListSource)), RefreshProperties(RefreshProperties.Repaint)]
public object DataSource
{
get{ return DataSource_m;}
set{ DataSource_m = value;}
}
}
[更新:您可能还需要RefreshProperties属性]
[回应评论]
这是我的课程:
[Update: you''ll probably also want the RefreshProperties Attribute]
[Response to comment]
This is my class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.ComponentModel;
namespace TestFormCSharp
{
class MyDataSourceClass:Control
{
object dataSource_m;
[AttributeProvider(typeof(IListSource)), RefreshProperties(RefreshProperties.Repaint)]
public object DataSource
{
get { return dataSource_m; }
set { dataSource_m = value; }
}
}
}
这就是我得到的:
http://yfrog.com/bfscreenshotdatasourcej [ ^ ]
如果您使用的是VS,那么您必须向我们展示更多的类声明和/或告诉我们您使用的是哪个版本的VS ...如果您使用的是VS;
and this is what I get:
http://yfrog.com/bfscreenshotdatasourcej[^]
If you''re not getting the same, then you''d have to show us more of your class declaration and/or tell us what version of VS you''re using...if you''re using VS;
这篇关于DataSource和DataMember属性(按代码)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!