如何使用外部函数更改devexpress控制值和属性 [英] How to change devexpress controls value and proprieties using external function

查看:74
本文介绍了如何使用外部函数更改devexpress控制值和属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





如何使用另一个类中的公共函数更改devexpress控件值和属性以变量形式(未知)...

ex: -



i有3个devexpess控件(标签,简单按钮,ComboBoxEdit),以及包含这3个控件(具有相同名称)的5个表单..



我还有另一个包含函数的类,当我以各种形式(需要时)调用此函数时,如何更改3个控件的值和属性?



我尝试了什么:



i试过这个:





how to change devexpress control value and proprieties exist in Variable form ( unknown ) using public function in another class ..
ex:-

i have 3 devexpess controls (label , simple button , ComboBoxEdit), and 5 form that contains this 3 controls (with same names)..

also i have another class that contains a function , how to change the 3 controls value and proprieties when i call this function in every form (when needed)?

What I have tried:

i tried this:

public static void  Search<T>(this XtraForm frm, IQueryable<T> query, BindingSource bindingsource, int currentPage = 1) where T : class
        {
frm.Controls["PAG_CountPerPage"].EditValue = "";
frm.Controls["PAG_CountPerPage"].SelectedText = "";
}





但是Control不包含EditValue,SelectedText,....的定义。



but Control does not contain definition for EditValue , SelectedText ,....

推荐答案

'frm.Controls'为你提供一个对象 - 而不是你想拥有的真实控件。

所以如果Type匹配,你必须把它投射到正确输入/访问您喜欢的房产类型。





此示例代码:

'frm.Controls' delivers you an Object - not the real control you want to have.
So you have to cast it, if the Type matches, into the right Type to get/access the Properties you like to have.


Sample-code for this :
Label myLabel;
if (this.Controls("Label1").GetType == typeof(Label))
    myLabel = this.Controls("Label1");

ComboBox myCombobox;
if (this.Controls("ComboBox1").GetType == typeof(ComboBox))
    myCombobox = this.Controls("ComboBox1");



现在您可以通过myLabel从Controls-Collection(当前表格)访问成员Label1

myComboBox也一样。

当然 - 你使用不同的控制 - 但制作是一样的。



如果有这个变量(myLabel或myCombobox)是没有什么在你的表格的Controls-Collection中没有这样的成员。


Now you can access the member "Label1" from the Controls-Collection (of the current Form) by "myLabel"
The same is with "myComboBox".
Of course - you use different controls - but the making is the same.

If one of this Variables (myLabel or myCombobox) is Nothing there is no such member inside the Controls-Collection of your Form.


这篇关于如何使用外部函数更改devexpress控制值和属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆