Refer to value type of a field on another form
:wave: Hi quite new to VB.2005 and I'm looking for some help please.
Let me tell what I want to achieve... probably is not the best approach how I'm trying to do but anyway... somebody might guide me.
I have an MDI form. From the menu I want to load a data bound form (MyDataForm) but before is shown I would like to restrict the records using another form (MyFilterForm) which would give the chance to the users to filter the data form.
So...
Code in the MenuItem:
Code:
Dim F as new MyDataForm
Dim s as new MyFilterForm
S.MdiParent=Me
S.OtherForm = F 'OtherForm is a Form varible on S
S.Show()
When loading S I need to loop trough all controls on OtherForm(F) to get:
1.Control name
2.Control type
3.Bound control IsValueType property
On my Filter form (S) the controls for selection will be created at runtime based on the above. I have to create controls with numbers, text, check boxes etc
I have managed to get 1 and 2 but I do not know how to refer programatically to get 3.
The ideea is to have form S as stand alone as possible. I could get all this information right at the beginning but I have manny forms using F and copy/paste the same code is not too "elegant".
I consider that ideally would be to be able to call like this:
Code:
Dim F as new MyDataForm
Dim s as new MyFilterForm
S.MdiParent=Me
S.OtherForm = F 'OtherForm is a Form varible on S
S.MyRelevantDataTable= "MyFormDataTable"
S.Show()
Then to get point 3, to loop in the 'MyFormDataTable' till I get the collumn and GetType its IsValueType... don't know how to do this. :eek2:
Can somebody give a steer please? I'm stuck at this point and searching on different forums but no success.
Thanks!
[2005] Re: Refer to value type of a field on another form
Re: Refer to value type of a field on another form
Re: Refer to value type of a field on another form
I am not sure if you are asking how to get the value type but if it is, then you can use the TypeOf keyword to in a condition statment. Since you know all the data types you have you can condition them like this:
vb Code:
if TypeOf(me) is Form Then
'do what ever you want
end if
Re: Refer to value type of a field on another form
I think you are going about it the wrong way in the first place. THe MDI parent should be creating and loading the MDI Child ONLY.... then in the constructor of the child form, create and show the filter form.
As for #3, I'm not 100% sure what you mean...
-tg
Re: Refer to value type of a field on another form
Hi
techgnome - that was the first thing I was dooing but when I was loaded the filter form, the main form was loaded too... this is what I wanted to avoid. If I have started in dialog mode the the filter form was mooving out of the Parent form area... I would like to keep it inside.
VBDT - What I want to access is the bound field IsValueType of a control on the form I want to filter. I need to set my filter form to validate if the user is trying to enter text in a numeric field. I was able to access if I explicitly specify the data table like:
Code:
Me.My_DataSet.MyDataTable.Columns(strColumnName).DataType.IsValueType()
I need to be able to aceess using the string name of these "My_DataSet", "MyDataTable". Something like
Code:
Dim m as New MainForm
If IsTheControlValueType(m,"MyDataSet", 'MyDataTable","AnyColumnName") Then _
MsgBox "This field is numeric and text is not accepted."
Public Function IsTheControlValueType(f as Form,strDataset as String, strDataTable As String, strFieldName As string) as Boolean
'I would like to achieve to get this property trough variables f, strDataset, etc. and not in form of:
'Me.My_DataSet.MyDataTable.Columns(strColumnName).DataType.IsValueType
End Function
Thanks.