Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,

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 = "";
}


but Control does not contain definition for EditValue , SelectedText ,....
Posted
Updated 10-Mar-19 22:18pm
Comments
[no name] 11-Mar-19 0:49am    
I see no relation between what you "say" you want and what you say you "tried".
Golden Basim 11-Mar-19 5:04am    
i'm sorry maybe i failed to explain what i want .. what i want is like that
 frm.Controls["PAG_CountPerPage"].EditValue = ""; 

1 solution

'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 :
C#
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");

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.
 
Share this answer
 
v2
Comments
Golden Basim 11-Mar-19 5:05am    
please can you show , how i can to do that ?
Golden Basim 11-Mar-19 6:03am    
i tried that but i failed
ComboBoxEdit PAG_CountPerPage = frm.Controls["PAG_CountPerPage"] as ComboBoxEdit;
            PAG_CountPerPage.SelectedIndex = 3;
Ralf Meier 11-Mar-19 7:08am    
Your code is a mix of VB and C# ...
In the moment I don't have a Visual Studio Version to use.
Also I'm not familiar enough with C# to give you a 'quick-and-dirty'-example.
Later (in the evening) I will create an example for you ...
Golden Basim 11-Mar-19 8:42am    
thanks
also i tried this code to check if the from have an issue or no >>


frm.Close();



and

frm.text = "change text";

and the code don't run , no thing happen no errors appear
Ralf Meier 11-Mar-19 15:37pm    
I added a/the code-sample ...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900