ā Simple project with C# windows forms app
Hello. I want to create an application which compares different offers and then gives the best offer. I am brand new to C#, that is why I need to know which elements I would use and how I would make the application responsive and dynamic and not hard coded. I want to use best practice C#.
I attached a picture of what I want it to look like. The column Criteria should initally be there. In the form on the left you can create a new offer which is then inserted in the table as a new column with the name as the column heading and the values of the inputs in the matching fields. The user should be able to add as many offers as they want to the table, not hardcoded amount. And when there is not enough space you should be able to scroll to the right to see the rest of the offers.
It would be nice if all the cells are getting smaller once you make the window smaller and same with the add offer form (responsive).
Can someone please guide me
44 Replies
You'd normally layout something like this by adding more rows, not adding columns
so "Price", "discount" etc would all be columns
First of all, "best practice" is to not use winforms these days, but if thats where you want to start you can.
I selected Windows Forms app
Some people in my class recommended it
but this seems pretty straight forward, you'd use textboxes and labels on the left side, and if you want that grid-view style on the right, there is a control for that called gridview
Thats fine, you can use winforms if you want. Just wanted to let you know since you asked for best practice
What would I use otherwise
WPF most likely
for a windows-only desktop GUI, WPF is the "default" but there are many alternatives.
Avalonia has windows/linux/mac support, for example
WPF-App from the visual studio templates? And what is the difference between windows forms app and the windows pressentation one
entirely different frameworks. WPF is declarative, kind of like html
I am very used to HTML, CSS and JavaScript. That is why Windows Forms was confusing to me
while winforms is... not. you use a drag and drop system and its really hard to get things to behave properly when resized š
then perhaps consider WPF
You mean GridDataView, right?
thats the one
Is it better to use than the TableLayoutPanel?
I was very confused on which one I would rather use
they are different. they look different, behave different
pick the one that does what you want.
I'm not a GUI expert by any means, but table layout panel doesnt look like what you want.
assuming we rotate the grid to make sense š
ie, scaling by row instead of column
Now I am also not sure if I choose "WPF-Application" or "WPF-App (.NET Framework)". Both an option here in the templates. For the latter it also says
XAML
never pick anything with ".NET Framework" in the name in 2023
thats the legacy version of .net
ah okay, so I will pick Wpf-app okay
yup.
i can stil drag and drop now though
but at the bottom i have this window
which is kind of like html
thats XAML, which is how we make things in WPF
dont use the drag and drop š
$rulesofwpf
Okay, now to summarize:
I will use a
GroupBox
for the sidebar to add an offer. Inside of that GroupBox
I use Labels
, Textbox
, and NumericUpDown
.
For the right I use DataGridView
.
And for the text at the bottom I use TextBlock
.
Does that sound good?sounds like a good sstart
it wont be too hard to change some of these, especially not with WPF
The only problem I had last time is that I used
DockStyle: Left
for the GroupBox
and then DockStyle: Fill
for the DataGridView
. And then the GroupBox
overlapped the DataGridView
I never figured it out how to have them side by sideso with WPF, thats easy to solve. you just make a grid with 2 columns, 1 row
and drop those things into that grid (groupbox on the left, a new grid on the right (since you want the gridview AND the text))
I definitely like the xaml more than the annoying drag and drop
Ah yes, two grid columns and then in the right column another grid. That is what you mean, right?
yup
damn this is so much easier than forms
thankk god
It does not support NumericUpDown unfortunately. Is there an alternative?
you could use a textbox, but if you really want specifically a numeric up down one, this toolkit contains one https://github.com/xceedsoftware/wpftoolkit
Alright, I think I will just use a TextBox. Another question, how would I make my DataGrid scrollable when all the columns do not fit on the screen?
ĀÆ\_(ć)_/ĀÆ
I still strongly recommend you let a row be the thing the user inserts thou
instead of a column
yes, that is what i am doing right now
there are very many columns
so its way more than just name price discount, like in your example?
yeah. Wait, I will send a screen
@Pobiega full screen app:
That is why i initially wanted columns for less side scrolling
Fair. Doesn't seem too bad thou.
Yeah, it is okay
Why is it so much harder to work with columns
Because thats how the control is intended to be used.
What I currently do to insert data also returns a bunch of errors
such as?
@Pobiega
xaml:
seems like having an anonymous object causes trouble
don't use anonymous types like that
make an actual type
Ah, the erros are from the columns which are not filled out by the form. They are initially empty and only calculated once the other cells are filled out
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.