Results 1 to 8 of 8

Thread: [2.0] using with w/ c#

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2006
    Posts
    719

    [2.0] using with w/ c#

    how can to avoid duplication of control like comboBox1?

    comboBox1.Items.Add("Item 1");
    comboBox1.Items.Add("Item 2");
    comboBox1.Items.Add("Item 3");


    just like in VB, it should be;

    with comboBox1
    .Items.Add("Item 1");
    .Items.Add("Item 2");
    .Items.Add("Item 3");
    end with

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] using with w/ c#

    Assign comboBox1.Items to a local variable and then refer to it each time C# has no direct equivalent to With.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2006
    Posts
    719

    Re: [2.0] using with w/ c#

    Assign comboBox1.Items to a local variable and then refer to it each time C# has no direct equivalent to With.

    how? kindly help me?

  4. #4
    Fanatic Member
    Join Date
    Jan 2005
    Location
    Cebu
    Posts
    607

    Re: [2.0] using with w/ c#

    Simply as JM said, there's no equivalent with With in C#. You more or less do it like this

    foreach (string s in new string[] {"a", "b", "c"}) { combo.Items.Add(s); }

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] using with w/ c#

    Quote Originally Posted by arshesander
    Assign comboBox1.Items to a local variable and then refer to it each time C# has no direct equivalent to With.

    how? kindly help me?
    Think first, ask questions later. You already know how to declare a local variable and assign something to it.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6
    Hyperactive Member BramVandenbon's Avatar
    Join Date
    Jan 2002
    Location
    Belgium
    Posts
    502

    Re: [2.0] using with w/ c#

    Let's give him a break, I think he really doesn't understand.

    Here it is:
    Code:
    ObjectCollection o = comboBox1.Items;
    o.Add("Item 1");
    o.Add("Item 2");
    o.Add("Item 3");
    ____________________________________________

    Please rate my messages. Thank you!
    ____________________________________________
    Bram Vandenbon
    http://www.bramvandenbon.com

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] using with w/ c#

    Quote Originally Posted by BramVandenbon
    Let's give him a break, I think he really doesn't understand.
    I disagree. I think people have a tendency to assume they don't understand without considering the problem properly. I very much doubt that arshesander has made it this far without having had to declare a local variable and assign a value to it. You may prefer to hand over a fish but I prefer to push people to learn to fish for themselves, especially when they already know how but don't realise it. In the long run that is more beneficial to someone's learning.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2.0] using with w/ c#

    I'll have to agree, this was way too simple to not understand.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width