Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 31st, 2012  |  syntax: None  |  size: 4.25 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How can i refer to a textbox that i don't know it's name?
  2. private: System::Void textBox_KeyPress(System::Object^  sender, System::Windows::Forms::KeyPressEventArgs^  e) {
  3.          if(e->KeyChar == '.')
  4.          {
  5.              if(this->/*the textbox in use*/->Text->Contains(".") && !this->/*the textbox in use*/->SelectedText->Contains("."))
  6.                  e->Handled = true;
  7.          }
  8.          else if(!Char::IsDigit(e->KeyChar) && e->KeyChar != 0x08)
  9.              e->Handled = true;
  10.      }
  11.        
  12. private void CreateTextBoxControls()
  13.     {
  14.         intColCount= Convert.ToInt32(txtColumnNo.Text.ToString().Trim());
  15.         int rowCount =0;
  16.         Table tblHead = new Table();
  17.         if (tblHead.GetType().ToString().Equals("System.Web.UI.WebControls.Table") && PHOptions.FindControl("tblHead") == null )
  18.         {
  19.             tblHead.ID  = "tblHead";
  20.             tblHead.EnableViewState = true;
  21.             tblHead.BorderWidth=Unit.Pixel(0);
  22.             tblHead.CellSpacing = 0;
  23.             tblHead.CellPadding = 1;
  24.             tblHead.Width = Unit.Percentage(96);
  25.             TableRow rH     = new TableRow();
  26.             TableCell cH    = new TableCell();
  27.             cH.Text= "Table Heading" ;
  28.             cH.Font.Bold = true;
  29.             rH.Cells.Add(cH);
  30.             tblHead.Rows.Add(rH);
  31.             PHOptions.Controls.Add(tblHead);
  32.             if(intColCount>0)
  33.                 rH.Visible =true;
  34.             else
  35.                 rH.Visible =false;
  36.         }
  37.  
  38.  
  39.         Table tblHelp = new Table();
  40.         if (tblHelp.GetType().ToString().Equals("System.Web.UI.WebControls.Table") && PHOptions.FindControl("tblHelp") == null )
  41.         {
  42.             tblHelp.ID  = "tblHelp";
  43.         }
  44.         tblHelp.EnableViewState = true;
  45.         tblHelp.BorderWidth=Unit.Pixel(1);
  46.         tblHelp.CellSpacing = 0;
  47.         tblHelp.CellPadding = 1;
  48.         tblHelp.BorderWidth = Unit.Pixel(1);
  49.         tblHelp.Width = Unit.Percentage(96);
  50.         for (int rowIndex=0; rowIndex<=rowCount; rowIndex++)
  51.         {
  52.             TableRow r      = new TableRow();
  53.             TableRow rWeight= new TableRow();
  54.             //r.ID          = "rLabel";
  55.             TableRow rID    = new TableRow();
  56.  
  57.  
  58.                 for (int clIndex=0; clIndex<intColCount; clIndex++)
  59.                 {
  60.                     TableCell c = new TableCell();
  61.                     txtBox = new TextBox();
  62.                     if (txtBox.GetType().ToString().Equals("System.Web.UI.WebControls.TextBox") && PHOptions.FindControl("txtOption"+(clIndex+1).ToString()) == null )
  63.                     {
  64.                         txtBox.ID ="txtOption"+(clIndex+1).ToString();
  65.                         //txtBox.Text = (clIndex+1).ToString();
  66.                         txtBox.Width= Unit.Pixel(45);
  67.                         txtBox.MaxLength = 2;
  68.                         c.BorderWidth=Unit.Pixel(1);
  69.                         c.Width=Unit.Pixel(80);
  70.                         c.Controls.Add(txtBox);
  71.                         r.Cells.Add(c);    
  72.                         txtBox.PreRender += new System.EventHandler(this.txtBox_PreRender);
  73.                     }
  74.                 }
  75.  
  76.             tblHelp.Rows.Add(r);
  77.         }
  78.         TableRow rSubmit        = new TableRow();
  79.         TableCell cSubmit = new TableCell();
  80.         cSubmit.ColumnSpan = intColCount ;
  81.         btnSubmitButton = new Button();
  82.         btnSubmitButton.ID  ="btnSubmit";
  83.         btnSubmitButton.Text= "Submit";
  84.  
  85.         if( PHOptions.FindControl("btnSubmit") == null )
  86.             cSubmit.Controls.Add(btnSubmitButton);
  87.         cSubmit.Attributes.Add("Align","Center");
  88.         rSubmit.Cells.Add(cSubmit);
  89.         tblHelp.Rows.Add(rSubmit);
  90.         PHOptions.Controls.Add(tblHelp);
  91.         this.btnSubmitButton.PreRender += new System.EventHandler(this.btnSubmitButton_PreRender);
  92.         this.btnSubmitButton.Click += new System.EventHandler(this.btnSubmitButton_Click);
  93.     }
  94.  
  95.  
  96.     private void btnSubmitButton_Click(object sender, System.EventArgs e)
  97.     {
  98.         for (int clIndex=0; clIndex<intColCount; clIndex++)
  99.         {
  100.             string boxName = "txtOption" + (clIndex+1).ToString();      
  101.             TextBox tb = PHOptions.FindControl(boxName) as TextBox;
  102.             if( lblDisplay.Text != "" )
  103.                 lblDisplay.Text+=","+tb.Text ;
  104.             else
  105.                 lblDisplay.Text=tb.Text ;
  106.         }
  107.     }