0

Please tell me. There are 2 grid controls. I also create 2 classes to fill these grid controls. The data is filled from the SQL Server database. Tables are one-to-many related. How to make when selecting 1 line from the first control to display the associated information on the second.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • What you describe is a Master-Detail scenario. Is there something that you have tried that is not working as expected? I suggest you peruse the SO [Tour](https://stackoverflow.com/tour) section as it shows how SO works. The [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask) may help. In addition, you may find the SO [Asking](https://stackoverflow.com/help/asking) section useful. – JohnG Feb 19 '21 at 06:00
  • Master-Detail displays information on one GridControl. And I have 2. On 1 Grid display information from the Users talitsa, and on 2 Grid information about the product. – Азат Гафаров Feb 19 '21 at 06:18
  • I have to disagree, a “Master-Detail” scenario, uses two (2) grids for a 1-to-many relationship. Example; grid 1 has rows of different Country names… when the user “selects” one of the rows in the country grid 1, then grid 2 would display the states/providence's for that “selected” country. In your case it is unclear how a user relates to a product or products. – JohnG Feb 19 '21 at 06:30
  • Tell me then how to display information on 2 GridControls? Without using string expansion – Азат Гафаров Feb 19 '21 at 06:47
  • Please forgive me if I am misunderstanding what you are asking. Can you give an example of what you are wanting to display in the two grids? And how the data is related? There are several ways to do this and, in most cases, depending on how the data is stored in the program (`List`, `DataTable`, `DataSet`) will dictate the best approach to set up a one to may relationship using two grids. I am not sure what you mean by “string expansion.” – JohnG Feb 19 '21 at 07:04
  • Again, you should move the text/code in your answer to the original question. The posted code appears correct and should work when using a `DataSet` with two tables. I do not understand what your question is.. _”I need to define a model for the GridControl”_ - _”and define the dataset class for the second table”_ … ? What is stopping you from doing this? You show a class called `Users` and you need to _”define the dataset class for the second table”_ ? Are you trying to use a `List` or a `DataSet`? This needs clarification. What is preventing you from defining the second table/class? – JohnG Feb 19 '21 at 09:53

1 Answers1

-1

Master-Detail Standard functionality

I do it differently 2 GridControl

Loading data using DataSet

DataColumn keyColumn = dataset1.Tables[0].Columns[0];
        DataColumn foreignKeyColumn = dataset1.Tables[1].Columns[4];
        dataset1.Relations.Add("armBuh", keyColumn, foreignKeyColumn);

        bindingSource1.DataSource = dataset1;
        bindingSource1.DataMember = "arm";
        
        bindingSource2.DataSource = bindingSource1;
        bindingSource2.DataMember = "armBuh";
        gridControl1.DataSource = bindingSource1;
        gridControl2.DataSource = bindingSource2;

I need to define a model for the GridControl

public class Users{
public int id { get; set; }
public string name { get; set; }}

and define the dataset class for the second table

For bindingSource, define DataSorse public class Users

How to display data on 2 GridControls by id in another table? DB layout

  • I can not tell if this solves your problem as an answer or should this answer be in the original question instead of an answer. I am guessing this is not an answer and you should move this into your original question. Click the “Edit” link below your question to edit and add this info. Do not add this info as an answer, edit your question. – JohnG Feb 19 '21 at 09:36