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

  • SEARCH
  • Home
  • 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 5966315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:46:54+00:00 2026-05-22T19:46:54+00:00

I have a class from which I want to get values from combo box

  • 0

I have a class from which I want to get values from combo box and textboxes, but when I pass the value it shows the following error:

An object reference is required for the non-static field, method, or property 

Here is the code

public class Device1
{
        public int dwMachineNumber = cboMachineNo.SelectedIndex;
        public int dwBaudrate = 9600;
        public int dwCommPort = CboComPort.SelectedIndex;
        public string dwIPAddress = tbIPAdd.Text.Trim();
        public int dwPort = int.Parse(tbPort.Text.Trim());
        public int dwPassWord = int.Parse(tbPwd.Text.Trim());
}

private bool OpenDevice(int flag)
{
    bool result = false;   
    int DEVICE_BUSY = 0;
    Device1 dww = new Device1();
    try{
       result = OpenCommPort(dww.dwMachineNumber,
                       dww.dwBaudrate, 
                       dww.dwCommPort, 
                       dww.dwIPAddress, 
                       dww.dwPassWord,
                       dww.dwPort,
                       flag);

}
  • 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-22T19:46:55+00:00Added an answer on May 22, 2026 at 7:46 pm

    Here, I think this is what you’re trying to do..

    You maybe want to create your Device1 class to look like this:

    public class Device1
    {
        public int dwMachineNumber;
        public int dwBaudrate;
        public int dwCommPort;
        public string dwIPAddress;
        public int dwPort;
        public int dwPassWord;
    
        public Device1(int dwMachineNumber, int dwBaudrate, int dwCommPort, string dwIPAddress, int dwPort, int dwPassWord)
        {
            this.dwMachineNumber = dwMachineNumber;
            this.dwBaudrate = dwBaudrate;
            this.dwCommPort = dwCommPort;
            this.dwIPAddress = dwIPAddress;
            this.dwPort = dwPort;
            this.dwPassWord = dwPassWord;
        }
    }
    

    Then in the code-behind of your Winforms form you need to add something similar to this:

        private void btnMyButton_Click(object sender, EventArgs e)
        {
            Device1 myDevice1 = new Device1(cboMachineNo.SelectedIndex, 9600, cboComPort.SelectedIndex, tbIPAdd.Text.Trim(), int.Parse(tbPort.Text.Trim(), int.Parse(tbPwd.Text.Trim());
    
            // Now do something with your populated Device1 object.
        }
    

    For this example, I added the code to the event handler of a button. You need to add it where you want it to happen.

    This code will take the values from the winform and pass them to the class. I believe this is what you want to do.

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

Sidebar

Related Questions

I have a class library which I want to call from my .NET application
I have a class which inherits from QTreeWidgetItem and I intercept the click event.
I have an abstract base class called Shape from which both Circle and Rectangle
I have a BasePage class which all other pages derive from: public class BasePage
I have a class SomeClass, which can populate itself from a datarow in it's
I have a WCF Web Service which is referenced from a class library. After
I have this sample text, which is retrieved from the class name on an
I have class A: public class ClassA<T> Class B derives from A: public class
I have a class that inherits from ObservableCollection(Of MyObject) and the MyObject class handles
I have a class A and another class that inherits from it, B. I

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.