Page 3 of 5 FirstFirst 12345 LastLast
Results 21 to 30 of 45

Thread: C#

  1. #21

    Default Re: C#


    Quote Originally Posted by Eisen Japhet Larnx View Post
    Good Evening mga programmers....

    Does any of you here know how to access a textbox from another form?....

    here's my codes:
    private void dataGridView1_DoubleClick(object sender, EventArgs e)
    {
    CreateAccount acc = new CreateAccount();
    acc.ShowDialog();
    acc.txtcid.Text = dataGridView1.CurrentRow.Cells[0].Value.ToString();
    acc.txtfname.Text = dataGridView1.CurrentRow.Cells[1].Value.ToString();
    }

    but txtcid and txtfname is inaccessible due to its protection level error...

    Option 1
    Make the access modifier to public - but I don't recommend this one, though it is easier, it is a bad programming practice.
    If you really want to expose this member variable, expose it through a property. (I recommend read-only for this case)

    Changing access modifiers of Form controls:
    Go to NameOfForm.Designer.cs
    you should see the member variable of the control like this (usually it is located at the bottom of the file. if i remember it correctly).

    private System.Windows.Forms.TextBox nameOfTextBox; <-- change private to public.

    Making a read-only property:
    If you choose this, then just make a property.
    e.g.

    public TextBox NameOfTextBox
    {
    get { return nameOfTextBox; }
    }


    Option 2
    Other way is, access it through Controls property.

    e.g.
    CreateAccount acc = new CreateAccount();
    TextBox text1 = acc.Controls["nameOfTextBox"] as TextBox;
    text1.Text = "desired value";

    NOTE: This assumes that the textbox is directly under the form. if it is inside another control, you have to make another instance for that to access it.

    Option 3
    Or you can also pass the values through the form's constructor. Then in the constructor assign the values to the textBoxes. I'm guessing that everytime you double click the grid, a form will pop so this might work for you too.
    This isn't accessing the control though, it is simply passing values to a form's control.

    e.g.
    CreateAccount acc = new CreateAccount(valForTxtbox1, valForTxtbox2);
    acc.ShowModal();

    in constructor:
    public CreateAccount(string cid, string fname)
    {
    InitializeComponent();

    txtCid.Text = cid;
    txtfName.Text = fname;
    }


    So far that's what I can think of. I hope this will help.

    Comment
    By the way, judging from the given code. The codes highlighted in red will not be executed unless the acc is closed, because, ShowDialog makes acc modal and when it reaches ShowDialog, it will halt in that area. Meaning, the value you assigned in the textboxes will not be reflected. I suggest placing it before ShowDialog.

    private void dataGridView1_DoubleClick(object sender, EventArgs e)
    {
    CreateAccount acc = new CreateAccount();
    acc.ShowDialog();
    acc.txtcid.Text = dataGridView1.CurrentRow.Cells[0].Value.ToString();
    acc.txtfname.Text = dataGridView1.CurrentRow.Cells[1].Value.ToString();

    }
    Last edited by Maikeru; 03-14-2011 at 01:48 PM.

  2. #22

    Default Re: C#

    damn! gusto nako magstart para makasabot ko sa inyong gi istoryahan . . . hahahaha ^^

  3. #23

    Default Re: C#

    Quote Originally Posted by marzzz21 View Post
    damn! gusto nako magstart para makasabot ko sa inyong gi istoryahan . . . hahahaha ^^
    Start na kalingawi lang gud..

  4. #24

    Default Re: C#

    nakuha na jud nk0....

    private System.Windows.Forms.TextBox txtcid; //havent notice your post about this..... thanks....
    ......
    changed the private to public.....
    naa ra mn d i ni sa CreateAccount.Designer.cs.......

    this is now the code:

    private void dataGridView1_DoubleClick(object sender, EventArgs e)
    {
    CreateAccount acc = new CreateAccount();
    acc.txtcid.Text = dataGridView1.CurrentRow.Cells[0].Value.ToString();
    acc.txtfname.Text = dataGridView1.CurrentRow.Cells[1].Value.ToString();
    acc.txtmname.Text = dataGridView1.CurrentRow.Cells[2].Value.ToString();
    acc.txtlname.Text = dataGridView1.CurrentRow.Cells[3].Value.ToString();
    acc.txtaddress.Text = dataGridView1.CurrentRow.Cells[4].Value.ToString();
    acc.txtcontact.Text = dataGridView1.CurrentRow.Cells[5].Value.ToString();
    acc.cmbcustype.Text = dataGridView1.CurrentRow.Cells[6].Value.ToString();
    acc.btnaccsave.Text = "UPDATE";
    acc.ShowDialog();
    }


    thanks for the advice.....

    Last edited by Eisen Japhet Larnx; 03-14-2011 at 10:04 PM.

  5. #25

    Default Re: C#

    This disc contains a "UDF" file system and requires an operating system
    that supports the ISO-13346 "UDF" file system specification.
    read me file ra lage ang sulod sa .iso na akong gi download gikan microsoft naggamit ko og powerISO na software . . . atay baya ani uy hehehe

  6. #26

    Default Re: C#

    Quote Originally Posted by marzzz21 View Post
    This disc contains a "UDF" file system and requires an operating system
    that supports the ISO-13346 "UDF" file system specification.
    read me file ra lage ang sulod sa .iso na akong gi download gikan microsoft naggamit ko og powerISO na software . . . atay baya ani uy hehehe
    Pwedi pud nimo iTry ang visual studio express. Dili lang pud noon complete ang iya features kay free raman. But, if for learning purposes guro, sufficient naman guro ni.

    Microsoft Express Downloads - Visual Studio Express and SQL Server Express

  7. #27

    Default Re: C#

    Quote Originally Posted by marzzz21 View Post
    This disc contains a "UDF" file system and requires an operating system
    that supports the ISO-13346 "UDF" file system specification.
    read me file ra lage ang sulod sa .iso na akong gi download gikan microsoft naggamit ko og powerISO na software . . . atay baya ani uy hehehe
    try using MagicISO to extract the ISO image or you burn the ISO image to a DVD. If you don't have Nero try using CDBurnerXP. When you burn the ISO to DVD be sure to select Burn ISO Image menu

  8. #28

    Default Re: C#

    try using alc0h0l 120

  9. #29

    Default Re: C#

    hay kailangan man diay ni sp3 na xp , hehehe hahayz hehehe, ako nalang ni i reformat akong pc human installan windows 7 na OS , , , hahaha ^^

  10. #30

    Default Re: C#

    dali ra jd kaau na makat.onan ang c# sir. over 3 years of my college cge lng ko atubang ug c#.

  11.    Advertisement

Page 3 of 5 FirstFirst 12345 LastLast

Similar Threads

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
about us
We are the first Cebu Online Media.

iSTORYA.NET is Cebu's Biggest, Southern Philippines' Most Active, and the Philippines' Strongest Online Community!
follow us
#top