Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing Selected Value in Combo Box in Another Class Results in Error
    primarykey
    data
    text
    <p>I've searched for several hours on how I would manage to do this, but none of the solutions I've found have worked...</p> <p>I have a form with several ComboBoxes, and I'd like to grab the selected values and use it in another class's method. The values will be used as variables in a filter to query a database. When assigning the values though, I got the error "An object reference is required for the non-static field, method, or property". I tried creating a new instance of the form in the other class, but wouldn't the new instance not have the ComboBox values I wanted in the first place?</p> <p>I'm not quite sure on how to do this. I've tried a bunch of ways but they've all failed.=/ I'm new to programming, so I would appreciate any help I can get!</p> <pre><code> public static void LoadMainTable(ref DataTable mainGridTable) { //Loads entires into a data table //FormMonitor FormMonitor = new FormMonitor(); string bankBox = FormMonitor.ComboBox1.SelectedItem; string theDate = FormMonitor.DateTimePicker.Value.ToString("yyyy-MM-dd"); //Grabbed in the order they will be displayed cmd.CommandText = String.Format("W.I.P."); //Add variables for filters after figuring out how to do it reader = cmd.ExecuteReader(); //reads data into dmainGridTable while (reader.Read()) { mainGridTable.Rows.Add(reader["column1"], reader["column2"], reader["column3"], reader["column4"].ToString(), reader["column5"].ToString(), reader["column6"]); //FormMonitor.file_ProgressUpdated(); //non-static error again, fix connect.Close(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload