Quantcast
Viewing all articles
Browse latest Browse all 12583

how to set property in custom datagridview column

Hi,

i have a custom datagridview column. Which is accept only numeric values.

The problem in that control have property decimalplaces which is accept number of decimal places in control.

in following code i don't know how to set decimalplaces property.

PrivateSub FrmTemp_Load(ByVal sender As System.Object,ByVal e As System.EventArgs)HandlesMyBase.LoadDim ColNum1 AsNew ColNumeric SigDataGridView1.Columns.Add(ColNum1)Dim ColNum2 AsNew ColNumeric SigDataGridView1.Columns.Add(ColNum2) SigDataGridView1.RowCount =10EndSubPublicClass ColNumericInherits DataGridViewColumnPublicSubNew()MyBase.New(New MaskedCellNum())EndSubPublicOverridesProperty CellTemplate()As DataGridViewCellGetReturnMyBase.CellTemplateEndGetSet(ByVal value As DataGridViewCell)' Ensure that the cell used for the template is a CalendarCell.If(value IsNot Nothing)AndAlso _Not value.GetType().IsAssignableFrom(GetType(MaskedCellNum)) _ThenThrowNew InvalidCastException("Must be a MaskedCellNum")EndIfMyBase.CellTemplate = valueEndSetEndPropertyEndClassPublicClass MaskedCellNumInherits DataGridViewTextBoxCellPublicSubNew()Me.Style.Alignment = DataGridViewContentAlignment.MiddleRightEndSubPublicOverridesSub InitializeEditingControl(ByVal rowIndex AsInteger, _ByVal initialFormattedValue AsObject, _ByVal dataGridViewCellStyle As DataGridViewCellStyle)' Set the value of the editing control to the current cell value.MyBase.InitializeEditingControl(rowIndex, initialFormattedValue, _ dataGridViewCellStyle)Dim ctl As MaskedEditingControlNum =CType(DataGridView.EditingControl, MaskedEditingControlNum)' Use the default row value when Value property is null.TryIf(Me.Value IsNothing)Then ctl.Text =Me.DefaultNewRowValueElse ctl.Text =Me.Value.ToStringEndIfCatch ex As Exception ctl.Text ="0.00"End Try

end subEndClassClass MaskedEditingControlNumInherits SigTextBoxImplements IDataGridViewEditingControlPublicSubNew()''''''''''''''''''OnErrorResumeNextMe.DataFormat = TxtFormat.NumericMe.DecimalPlaces =2Me.PromptChar =" "Me.ReadOnly=FalseEndSubEndClass


In Class MaskedEditingControlNum the new procedure have code line Me.Decimalplaces = 2, this is fix and i want set this property to run time how i do this.


Art Of Living Is Art Of Giving


Viewing all articles
Browse latest Browse all 12583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>