C
C#Nobody

❔ Show values from a list in a datagridview getting source from bindingsource

Hello! I have the following problem: I am currently developing a winforms app with a datagridview that takes its information from a bindingsource. In this bindingsource i have multiple objects based on my materials class. Every material have two variables, one for its name and a list for other objects that each material should have. Every material have the same number of objects in this list and they all have the same name. I cant seem to figure out how to do this however.
M
MasterSubarashii392d ago
can you provide some code and screenshots? or try DataGridView.DataSource=bindingsource.ToList();
N
Nobody392d ago
Well I think i was rather unclear with what I wrote. I will include some screenshots what will hopefully explain it better. I have this class MaterialModel with represents different materials.
N
Nobody392d ago
N
Nobody392d ago
The consumables is a list of consumablemodels, which needs a value, name and unit. Its to string method gives back its value and unit.
N
Nobody392d ago
N
Nobody392d ago
My datagridview takes a list of material models which it puts into its bindingsource. I get the following output to it:
N
Nobody392d ago
N
Nobody392d ago
For each of these materials (test1, test2, test4) I would like its consumables to appear next to them, but also maintain that it material models since I have implemented the method to remove materials by clicking them and hitting a button. It is connected to a pgsql database which stores the materials and retrieves them Here is the method that loads all the materials into the list which is later used in the bindingsource
List<MaterialModel> materials = new List<MaterialModel>();

using (var conn = new NpgsqlConnection(connectionString))
using (var cmd = conn.CreateCommand())
{
conn.Open();
cmd.CommandText = "SELECT * FROM AllInformationConsumables";
cmd.Connection = conn;
using (var reader = cmd.ExecuteReader())
{
while(reader.Read())
{
MaterialModel material = new MaterialModel();
material.Consumables = new List<ConsumableModel>(); //Vi hämtar data härifrån fast det är null, need to fix.
material.Name = reader.GetString(0);
for(int i = 1; i <= reader.FieldCount-1; i++)
{
ConsumableModel con = new ConsumableModel();
con.Name = reader.GetName(i); //DENNA FUCKAR ALLT, var off by one error :D
string[] valueUnit = reader.GetString(i).Split(" ");
con.Value = Convert.ToDouble(valueUnit[0]);
con.Unit = valueUnit[1];
//MessageBox.Show(con.ToString());
material.AddConsumable(con);

}
materials.Add(material);
}
}

}
return materials;
}
List<MaterialModel> materials = new List<MaterialModel>();

using (var conn = new NpgsqlConnection(connectionString))
using (var cmd = conn.CreateCommand())
{
conn.Open();
cmd.CommandText = "SELECT * FROM AllInformationConsumables";
cmd.Connection = conn;
using (var reader = cmd.ExecuteReader())
{
while(reader.Read())
{
MaterialModel material = new MaterialModel();
material.Consumables = new List<ConsumableModel>(); //Vi hämtar data härifrån fast det är null, need to fix.
material.Name = reader.GetString(0);
for(int i = 1; i <= reader.FieldCount-1; i++)
{
ConsumableModel con = new ConsumableModel();
con.Name = reader.GetName(i); //DENNA FUCKAR ALLT, var off by one error :D
string[] valueUnit = reader.GetString(i).Split(" ");
con.Value = Convert.ToDouble(valueUnit[0]);
con.Unit = valueUnit[1];
//MessageBox.Show(con.ToString());
material.AddConsumable(con);

}
materials.Add(material);
}
}

}
return materials;
}
A
Accord391d ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server
More Posts
❔ Render email content .NET 7 (razor)I have to reinplement email content rendering, because currently its not looking really good, especi❔ GetAxis wont workpublic class Driver : MonoBehaviour { // Start is called before the first frame update const✅ (SOLVED)Help a Beginneri am following CodeMonkeys 11Hr youtube video on coding a game in unity. I have ran into a issue whe❔ Exclude items from linq query if they contain one from an array of substringsI've got a list of strings, that if they appear anywhere in a linq query column i want to exclude th✅ Comprehension questions (LeetCode Binary Search)Like the title says it's about this puzzle https://leetcode.com/problems/binary-search/description/ ❔ How to create a cubic function calculator that also calculates the minimum and maximum value```c Console.WriteLine("Please enter a, b, c, d for the cubic function ax^3+bx^2+cx+d"); ❔ how to listen to the output of a virtual audio device on windows using C#?how to listen to the output of a virtual audio device on windows using C# to save the raw audio stre❔ How to wait for process to completei want to make program opens async but instead of giving 'hard coded' delays but i don't know how to❔ Problem with including C DLL in a C# console app project.So I have this C DLL imported into my console app (.NET 5). I simply cannot get to call it correctly✅ Win Form Event Handlers questionHi, I was just wondering if there is an event handler when the win form is idle that I can then run ❔ Problem with Dictionary<ulong, Image> (Strange work of memory access)Concept of my system: A system that draws a picture with stickers, each of the stickers can be moved❔ How do I refactor this?I am working with a grid of tiles, each tile has an int, which is made up of 4 bytes which represent❔ [AvaloniaUI] Visibility of item in ListView based on conditionAn Avalonia UI application is used to manage an evidence of items. It allows the user to add items. ✅ How to structure this login/signup page layoutSo I have this mockup of the layout I want for a login/signup page in my Blazor WASM app. Pretty sta❔ I am need of help before I give up and run my code on a server instead of a serverless solution.I have create an azure function locally and i've used the selenuim webdriver package for taking scre✅ .Net Core 6 Asymmetric Encryption with custom public and private keysHello all! How can i use the `Asymmetric Encryption` in .Net 6 but choosing/importing private and pu❔ No Design in C#Instances of this bug (1) 1. View Call Stack at System.Runtime.InteropServices.Marshal.ThrowExce❔ having issues on a reloading script on unity to reload weaponsthe code is used in a youtube video and i have pretty much copied to to get it to work but it doesnt❔ help with an exerciseI've encountered a weird problem that idk how to fix. Say we've got a string "31131123521" how do i ❔ Accessing HTTP Context at DbCommandInterceptor [.NET 7]Hi! I'm having some issues trying to access the HTTP Context at my DbCommand Interceptor class. What