C
C#SCOLANATOR

❔ Problem populating Datagrid

I'm trying to populate a datagrid where certain columns are populated with information that is read only, with the other columns open for a user to input data and with one column with a checkbox binary option. I have been struggling to get this code to work and would appreciate some help. I'm very new to WPF and C# (done a lot of VB6 and PoSh, some C, some Python). Please let me know how I should post my code.
B
Buddy397d ago
$details
M
MODiX397d ago
When you ask a question, make sure you include as much detail as possible. Such as code, the issue you are facing, and what you expect the result to be. Upload code here https://paste.mod.gg/ (see $code for more information on how to paste your code)
S
SCOLANATOR397d ago
BlazeBin - uirbfxijpapy
A tool for sharing your source code with the world!
M
MODiX397d ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat If your code is too long, post it to: https://paste.mod.gg/
S
SCOLANATOR397d ago
These are the errors that are popping up
K
Klarth397d ago
tax_election_grid.DataSource = data; I don't understand why you're using this array as if it's a DataGrid? DataGridViewCheckBoxColumn chkBoxColmn = new DataGridViewCheckBoxColumn(); for this type not being found, you can ctrl+. in VS (or click the light bulb) when the cursor is on top of the red squigglies. VS should suggest to automatically add the using statement for the necessary namespace.
S
SCOLANATOR397d ago
Thanks Klarth, I pulled this from somewhere and modified it for my needs. So I'm not sure why it's done the way it is, I just started with C# so I'm trying to get to grips with it. So for datagridviewcheckboxcolumn should I create a new private class?
K
Klarth397d ago
No.
K
Klarth397d ago
This error means that the correct namespace hasn't been referenced, so the compiler cannot resolve the type.
S
SCOLANATOR397d ago
Is there a better example I can use to populate datagrid? I'm absolutely pulling my hair out trying to get this to work. I feel like it shouldn't be this difficult to populate a data grid with an array.
K
Klarth397d ago
Now that I look at it, I think you're following an example from WinForm's DataGridView and not WPF's DataGrid.
K
Klarth397d ago
K
Klarth397d ago
See how it suggests the WinForms namespace. You should probably start by replicating https://wpf-tutorial.com/datagrid-control/introduction/ As far as having check-able state, you're going to hit a wall pretty fast because you likely don't understand data binding or INotifyPropertyChanged yet. Ah, autogeneration takes care of one half of that equation. You still want data binding / INotifyPropertyChanged for when you change state in code-behind though.
K
Klarth397d ago
K
Klarth397d ago
https://paste.mod.gg/jjbpmfuzqubn/0 and https://paste.mod.gg/yppjuapszhpr/0 Only code-behind. If you modify the users in code-behind, it won't automatically reflect in the GUI because the correct abstractions (ObservableCollection<T> and INPC) weren't used.
S
SCOLANATOR397d ago
Thank you Klarth, that's a good explanation to work with. I have actually come across INotifyPropertyChanged but I haven't messed with it yet. i really just need to get these grids functioning properly and it should be fairly smooth sailing after that While I'm at it, is there a simple way to take an integer and use it to give a datagrid that many rows? That guide you gave me really helps
K
Klarth397d ago
That's not really something you should do. You can create N empty objects (eg. Users) and add them the source. For INotifyPropertyChanged, I would either: 1. grab an implementation from https://stevemonaco.github.io/2020/08/wpf-2020-part2-mvvm-overview/ (disclaimer: I wrote the article) or 2. read the article for a basic understanding and instead use CommunityToolkit.Mvvm from NuGet which provides significantly better implementations of most MVVM things you'd ever need. The docs are also pretty good.
S
SCOLANATOR397d ago
I'll read through these and get back to you if I have any follow up questions
A
Accord396d 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
❔ Avisynth script maker thingIm trying to make a script that creates AVS files for every file in a Directory based on a template.❔ How to work with Hwnd in c#I want to open programs using Process.Start but all those programs have empty MainWindowHandle and M❔ VS For Mac Code CoverageHas anyone figured out how to show which lines are covered after running unit tests in VS For Mac?✅ Run code in main thread after Task.Run completed?Hello, I have a long running void function that I execute in a separate thread by calling `Task.Run(❔ methodHello, If I create a method, does the method know about things in the Main method? Or am I supposed ❔ Project structure1. In my Solution there should be only 1 Project right? Unless its a big App 2. I started using fo❔ how to use EF6 in library with no dependancy injection and no startup.csI used EF core power tools to generate DB Context and reverse engineer the models. now I get an erro❔ HeadFirst Design PatternSo I started with this Book today. First problem starts with the Duck Project: and when he tests h✅ EqualityComparerHello, anyone know of this code work ? --> `EqualityComparer<ICollection<myclass>> .Default.Equals❔ error attaching script (unity)this error appears when trying to attach the script, does anyone know how to solve it?❔ i have an app that runs well on my pc but not on other pcsi have an app that runs well on my pc but on when i zip it and bring it to another pc the ui is all yield???```cs public IEnumerable<int> A() { for (int i = 0; i <= 10; i += 2) yield return i; } C# Data Table issuehttps://pastebin.com/DSHwSh0M based on this program, I need to set the values of the `Old PS A11Y S❔ Microsoft Graph SDK - Serializing objectsHello, I am currently working with Microsoft Graph API to work with the Planner. My goal is to backu❔ XML deserialise different types into a single listI'm using the build in XML serialisation library (unless it's with .NET framework?), and I current h❔ Access things from different scene in UnityI have a Class Selector scene that has a Class Selector Script component (MonoBehaviour) attached to❔ C# how do I write an If-statement to handle a button?Hi, I wanted some assistance with writing a If-statement that filters out the zones section in my ap❔ Magnetic Links for application?Hey, does someone have an article/tutorial/explanation how I can develop magnetic links for my appli❔ Show values from a list in a datagridview getting source from bindingsourceHello! I have the following problem: I am currently developing a winforms app with a datagridview th❔ Render email content .NET 7 (razor)I have to reinplement email content rendering, because currently its not looking really good, especi