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

This is a question that I am raising for a second time.

I had created the Textboxs and comboboxs in runtime.

I want to find that control's name and I want to use its properites at run-time only.

Is it possible to find the name of the controls at that particular instant of time?

I am not able to acess the find method. Can anyone explain clearly?

Thank you for your attention.
here i am going to do some sample the code that what i had done;

Canvas a = new Canvas();
               a.Height = 30;
               a.Width = 715;
               a.Name = "Pan" + i.ToString();
               a.Background = Brushes.PowderBlue;
               a.Margin = new Thickness(3, t + height, 0, 0);
               if (i >= 2)
               {
                   productspan.Height = productspan.Height + 40;
               }
               productspan.Children.Add(a);
               height = height + 40;
               Label l1 = new Label();
               l1.Content = "Item Name";
               l1.Margin = new Thickness(5, 5, 0, 0);
               a.Children.Add(l1);
               ComboBox cb = new ComboBox();
               cb.Width = 120;
               cb.Name = "cbsitems" + i.ToString();
               OleDbCommand cmd = new OleDbCommand("select * from stocktable where remain >=0 order by remain desc", con);
               OleDbDataReader dr;
               connect();
               dr = cmd.ExecuteReader();
               while (dr.Read())
               {
                   if (dr["item"].ToString() != "New")
                   {
                       cb.Items.Add(dr["item"].ToString());
                   }
               }
               cb.Items.Add("Select");
               cb.SelectedItem = "Select";
               diconnect();
              cb.SelectionChanged += new SelectionChangedEventHandler(cb_SelectionChanged);
               cb.Margin = new Thickness(70, 5, 0, 0);
               a.Children.Add(cb);

               Label l3 = new Label();
               l3.Content = "Amount/item";
               l3.Margin = new Thickness(200, 5, 0, 0);
               a.Children.Add(l3);
               TextBox tx1 = new TextBox();
               tx1.IsReadOnly = true;
               tx1.Margin = new Thickness(275, 5, 0, 0);
               tx1.Width = 100;
               tx1.GotFocus += new RoutedEventHandler(tx1_GotFocus);
               tx1.Name = "pritxt" + i.ToString();
               a.Children.Add(tx1);


here first am creating

label-....
combobox-"cbsitems" + i.ToString();
label-....
textbox-"pritxt" + i.ToString();

my requirement is that when the comobobox selection changed , then selected item price should be apper in the textbox; iam able to retrive the price from the table, more over i am facing the problem with placing the price in the textbox(which was created dynamically )
i think right now u can understand my problem
Posted
Updated 17-Nov-10 1:16am
v3
Comments
Dalek Dave 17-Nov-10 3:37am    
Edited for Grammar, Spelling, Syntax and Readability.

I don't quite understand. You created the textboxes and comboboxes
at runtime so you already have a reference to them (that could be stored
in any convenient data structure / object of your choosing).
What is is you're trying to achieve?
Show some code (simplified to the essentials at best) to illustrate
your issues.

Cheers

Manfred
 
Share this answer
 
Comments
[no name] 17-Nov-10 7:39am    
hi i had posted the sample code, see that once
Hi sivakumarmr10,

How are you adding your controls? If you're using WPF it may be possible to bind a "ContentPresenter" to a List in your "CodeBehind" file or "ViewModel" class, depending on your methodology and then iterate through that list, picking out the control you're looking for.

The list that you create, could be a list of your own predefined type, this type could then have a property such as unique identifier. When iterating through this list, you could retrieve the control that you need depending on that attribute.

You can define the type of control inside a data-template of your newly created type.

XML
<DataTemplate DataType="{x:Type MyClass}">
    <Button/>
<<DataTemplate />


Then in your XML file :

XML
<Border BorderThickness="1" Background="White">
    <ScrollViewer>
        <ItemsControl ItemsSource="{Binding MyClassDP}" />
    </ScrollViewer>
</Border>


Depending on the data context of your code behind you may then wish to set a dependency property in either the code behind or a separate class, naive to your .xaml.cs file :

C#
#region MyClassDp
/// <summary>
/// MyClassDp Dependency Property
/// </summary>
public static readonly DependencyProperty MyClassDpProperty =
    DependencyProperty.Register("MyClassDp", typeof(List<MyClass>), typeof(Program),
        new FrameworkPropertyMetadata((List<MyClass>)null));
/// <summary>
/// Gets or sets the MyClassDp property. This dependency property
/// indicates a list of my custom class.
/// </summary>
public List<MyClass> MyClassDp
{
    get { return (List<MyClass>)GetValue(MyClassDpProperty); }
    set { SetValue(MyClassDpProperty, value); }
}
#endregion



I hope this helps, apologies if that's not the approach you're going for. I have given a similar answer to this one elsewhere in relation to WPF data-bindings which might help.

Credit to DR WPF for DP Auto-Generated Snippet.
 
Share this answer
 
v2

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