Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 254891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:53:06+00:00 2026-05-11T21:53:06+00:00

The issue I’m currently having is mapping multiple GUI fields to object properties (i.e.

  • 0

The issue I’m currently having is mapping multiple GUI fields to object properties (i.e. Presentation layer to Business Logic Layer mapping). To be more specific, this is in VB.Net 2.0 WinForms.

The nature of the solution requires us to have 4 columns which exhibit the same type of behavior on our GUI – each column consisting of 11 textboxes (we’ll just use this small sample size, as the problem extends beyond 11 textboxes).

What I am currently doing is setting the tag of each textbox in all four columns to a value like so:

Textbox1.tag = "name"
Textbox2.tag = "type"
Textbox3.tag = "speed"

When an event is raised by the textbox (e.g. keypress), I look at the parent container, whose tag I have also set as a string mapping a specific object. I use that, in conjunction with the textbox’s tag, to determine what object’s property I need to set. Overall, it looks something like this:

dim objectToMapTo //the generic parent object which all my custom myObjects inherit from

select case sender.parent.tag //the parent object that the property needs to map to
    case "column1"
         objectToMapTo = myObject1
    case "column2"
         objectToMapTo = myObject2
    case "column3"
         objectToMapTo = myObject3
    case "column4"
         objectToMapTo = myObject4
end select

select case sender.tag //the actual textbox's tag value which maps to the property
    case "name"
         objectToMapTo.Name = sender.text //sender.text is conceptual for 
        //the data that needs to be set -- i.e. this could be a calculated 
        //number based on the text, or simply a string, etc
    case "type"
         objectToMapTo.Type = sender.text
    case "speed"
         objectToMapTo.Speed = sender.text
    ...
end select

As you can see this can get very bad, rather quickly. Currently we’re setting 43 some odd properties that can be mapped to — thus that select statement is extremely long — many of which are embedded in multiple methods to try and attempt DRY (I’ve watered down the code to essentially a conceptual implementation).

Question is: how can I refactor this? I’ve attempted using a dictionaries/hashes to a certain extent, but it either became overly complex, or just plain didn’t make an implementation sense as it convoluted the problem even more.

Thanks for the help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T21:53:06+00:00Added an answer on May 11, 2026 at 9:53 pm

    the first problem you sol by setting the tag as the object. Since tag is not string but of type object.

    And the second problem you solve by usin reflection but than the value in the tag must match the propertyname exactly.

    _objectToMapTo.GetType().InvokeMember(sender.tag,BindingFlags.Instance Or BindingFlags.Public,Nothing, _objectToMapTo, New Object() {sender.text})
    

    Disclaimer the reflection is close but perhaps not 100% correct.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 175k
  • Answers 175k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can rename the xap to zip, extract it, and… May 12, 2026 at 2:59 pm
  • Editorial Team
    Editorial Team added an answer A good place to start is the ISO website (perhaps… May 12, 2026 at 2:59 pm
  • Editorial Team
    Editorial Team added an answer This site explains the difference between those operators. But essentially,… May 12, 2026 at 2:59 pm

Related Questions

I am currently running into a problem where an element is coming back from
I have a JSP page retrieving data and when single or double quotes are
The issue I have is as follows: My company's supplier gives us an Access
The issue I'm currently having is mapping multiple GUI fields to object properties (i.e.
Here is the issue I am having: I have a large query that needs

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.