c# Filling DataGridView without empty cells



  • Hello, everyone. We need to insert Dictionary values into dgv. How do you put these values right in the table so that they don't start every time with a new line? введите сюда описание изображения

    Yeah, I understand that I'm just putting in a new line. It would be useful to know how data could be inserted in the previously established line.

    Code:

                var Dictionary = BusinessMenu.dic;
                foreach (var Product in Dictionary.Values)
                {
                    switch (Product.Type)
                    {
                        case "Business":
                            dgv.Rows.Add($"{Product.Title}/{Product.Price}", null, null, null, null, null);
                            break;
                        case "Salad":
                            dgv.Rows.Add(null, $"{Product.Title}/{Product.Price}", null, null, null, null);
                            break;
                        case "Soup":
                            dgv.Rows.Add(null, null, $"{Product.Title}/{Product.Price}", null, null, null);
                            break;
                        case "HotDishes":
                            dgv.Rows.Add(null, null, null, $"{Product.Title}/{Product.Price}", null, null);
                            break;
                        case "Dessert":
                            dgv.Rows.Add(null, null, null, null, $"{Product.Title}/{Product.Price}", null);
                            break;
                        case "Drinkable":
                            dgv.Rows.Add(null, null, null, null, null, $"{Product.Title}/{Product.Price}");
                            break;
                    }
                }
    


  • We could use a specific cell.

    dataGridView1.Rows[1].Cells[1].Value = "Tets";
    


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2