Good day!
I do a search in the MSSQL database. Tables are loaded into it from FIAS (Federal Information Address System).
The question is that you need to select the value of ONE (FORMALNAME) column in the table (city district) in the same combobox as the streets again (FORMALNAME), and the combobox should be independent, at the end after pressing the search button, it should issue DBGrid search base, i.e. values ​​that I found.

  • 2
    What is a DBGrid ? You have a WinForms project, right? - Ev_Hyper
  • DBGrid - database table, That's right WinForms project - Panstone

1 answer 1

Greetings

The answer is calculated on the fact that you already know how to receive data from the database server on the client side.

Sample data using LINQ in List<ComboGuidItem> .

ComboBox initialization is represented in the setCombo() method

valueList - List<ComboGuidItem> .

DisplayMember string name of the property of the ComboGuidItem class, whose data will be displayed to the user in the ComboBox . In our case, you need to pass the string "member" .

ValueMember is the string name of the property of the ComboGuidItem class, whose data will be behind each list item in the ComboBox (IDshnik in the database). In our case, you need to pass the string "value"

The ID value after the user selects for further query to the database, get from the property Guid id = (Guid)cb.SelectedValue;

On request, convert the received data from the server to a DataTable or List<T> and output it to the DataGridView through its DataSource property.

 public class ComboGuidItem { public Guid value { get; set; } public string member { get; set; } } public static void setCombo(ComboBox cb, object valueList, string DisplayMember, string ValueMember) { cb.DataSource = valueList; cb.DisplayMember = DisplayMember; cb.ValueMember = ValueMember; } 
  • Thank you so much for your reply! I will definitely report the result - Panstone