用户控件创建属性 [英] user control create property
问题描述
hai
我通过继承名为Numbox的DataGridViewColumn使用datagridview创建了一个用户控件.
I have created one user controll using datagridview by inheriting DataGridViewColumn called Numbox.
我添加了一个用于输入格式的属性.我的错误是,当我在窗体上使用此控件并添加2个以上的numbox列并为一个列设置属性时,所有列都更改为相同的属性.
I have added one property for entering format. My error is when i use this control on form and add more than 2 numbox column and set property for one column, all the column is changed to the same property.
例如,当我将column1 formatstring属性更改为0.00时,column2也更改为0.00,但是我希望column2设置0.000
for eg when i change column1 formatstring property to 0.00 then column2 also changed to 0.00, but i want column2 to set 0.000
请告诉我我的代码出了什么问题.
please tell what is wrong with my code.
我使用下面的代码
私人共享m_FormatString作为字符串
Private Shared m_FormatString As String
公共类DataGridViewNumBoxColumn
继承DataGridViewColumn
Public Sub New()
MyBase.New(New NumboxCell())
MyBase.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
结束
Public Class DataGridViewNumBoxColumn
Inherits DataGridViewColumn
Public Sub New()
MyBase.New(New NumboxCell())
MyBase.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
End Sub
公共属性FormatString()作为字符串
获取
返回m_FormatString
结束获取
设置(ByVal值作为字符串)
m_FormatString =值
端套
最终财产
结束班
Public Property FormatString() As String
Get
Return m_FormatString
End Get
Set(ByVal value As String)
m_FormatString = value
End Set
End Property
End Class
推荐答案
因为您将m_FormatString声明为共享.删除共享关键字,它将起作用.
Because you are declaring m_FormatString as shared. Remove shared keyword and it will work.
这篇关于用户控件创建属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!