|
My Bad
It's a rectangle, with 1 combo at the top, then 3 textboxes underneath.
No add / remove buttons, they are at the top of container, outside the user control.
I tried to draw a picture with text, didn't work out.
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
Right - so it has to be a UserControl, and you need to have an "expanding" collection control to put them on.
I'd probably start with a FlowLayoutPanel - but it depends on how you want to arrange them.
Every time you click the button, it adds another item to it and flows them around to fit:
private void button1_Click(object sender, EventArgs e)
{
Button b = new Button();
b.Text = $"Hello: {++buttonsCount}";
b.Click += MyAddedButton_Click;
myFlowLayoutPanel.Controls.Add(b);
}
private int buttonsCount = 0;
private void MyAddedButton_Click(object sender, EventArgs e)
{
Console.WriteLine((sender as Button)?.Text);
}
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Good call.
I changed the panel to the flow layout panel, went top to bottom.
This is really cool! This panel automatically positions my user control perfect and makes a scroll bar when needed.
I'm in the process of wiring it all up now, so far so good. No different than passing data from a form to a dialog.
You can't see me, but I have a huge smile on my face. And I know I choose the right path.
I'm very happy with .Net Core Win Forms using direct injection, so far it's working great for me. I love using the app I made with this technology.
Thanks Griff!
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
You're welcome!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
So I deleted the control off the dialog box, and decided to create the control in code.
This is where I got confused.
I made a panel, set the sizes up static, and wrote some code, where I click on "ADD", and add the user control to the panel.
I did figure out the direct injection part, injecting my inventory repository, and when adding the control the Item list populates.
It's a start at least. Just need to calculate the next box location. I can relate to this, and will test it out and see how it goes before I abandon the idea. Maybe I should be using that Flow Panel control.
private void Btn_Add_Click(object sender, EventArgs e)
{
var ucCount = panelItems.Controls.Count;
var ucLocation = new Point(0, 0);
var shipmentControl = new AmazonFBAShipmentControl(inventoryRepository);
shipmentControl.Location = ucLocation;
panelItems.Controls.Add(shipmentControl);
}
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
I have this query:
var currentYearData = (from p in db.Projects
join co in db.Companies on p.CompanyId equals co.Id
join cty in db.Cities on p.CityId equals cty.Id
join j in db.Jobs on p.Id equals j.ProjectId
join jsdr in db.JobStartDateRevisions on j.Id equals jsdr.JobId
where jsdr.StartDate >= start && jsdr.StartDate <= end
select new { p, c=co, cty, j, jsdr })
.OrderBy(x => x.c.CompanyName)
.ThenBy(x => x.p.ProjectName)
.ThenBy(x => x.jsdr.StartDate)
.ToList();
Where I join on JobStartDateRevisions, I only want to join to the NEWEST JobStartDateRevision record.
Is this possible? Can someone show me how to do this?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
You don't join on a condition you need to filter the set to get what you want. You could try by ordering the set by StartDate descending and then take 1 record from the top of the set.
"I didn't mention the bats - he'd see them soon enough" - Hunter S Thompson - RIP
|
|
|
|
|
While Nullable Reference Types are great, in some ways they just kick the problem down the road. In a workflow an object may allow a field to be null in an early step, but mandatory in a later step. I call these Temporal Nulls . If we want our objects to accurately reflect the business case/state NRT's introduce a new design decision. How are you approaching this?
Explainer
In Step 1 I am gathering data. Assume I am not creating the object here, just adding Info data.
In Step 2 I am using the data. At this point Info is required data.
The object is the same object from a business perspective, but from a technology perspective it has two states.
class MyInfo {
public InfoData? Info;
}
class MyInfo {
public InfoData Info;
}
I can think of three general approaches to this.
1. Use multiple classes
2. Use properties or multiple fields
3. Use defaults
The multiple class approach (above) is the most "accurate" but multiplies maintenance and would require different names for the classes (e.g., MyInfo & MyInfoWip).
A property or multiple field approach can look something like this
class MyInfo {
private _infoData?;
public InfoData {
get => _infoData ?? throw ...
set => _infoData = value
}
}
The drawback here is that I've basically exchange a null for an error and I don't know until I try to use it.
The defaults approach is getting common using Empty
class MyInfo {
public InfoData = InfoData.Empty;
public static InfoData Empty => new InfoData();
}
This is just kicking the can. I've replaced a null check with a "Empty Check". It requires defining what Empty values required fields get - new InfoData(emptyValues) .
What other approaches come to mind, and how do you normally deal with Temporal Nulls?
|
|
|
|
|
private string _info = null;
public string Info { get { return _info ?? "I'm empty"; } set { _info = value; } }
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
|
I suggest you look at the new static analysis features/attributes in C# 8: [^]
Quote: AllowNull: A non-nullable input argument may be null.
DisallowNull: A nullable input argument should never be null.
MaybeNull: A non-nullable return value may be null.
NotNull: A nullable return value will never be null.
MaybeNullWhen: A non-nullable input argument may be null when the method returns the specified bool value.
NotNullWhen: A nullable input argument will not be null when the method returns the specified bool value.
NotNullIfNotNull: A return value isn't null if the argument for the specified parameter isn't null.
DoesNotReturn: A method never returns. In other words, it always throws an exception.
DoesNotReturnIf: This method never returns if the associated bool parameter has the specified value. I recommend Jonathan Allen's coverage of these features on InfoQ: >[^]
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
modified 28-Oct-20 5:06am.
|
|
|
|
|
Hi guys
I need your help with developing this program...
Using C# Console application, design a program that uses nested for
loop statements to display students and their respective locations in a string matrix.
|
|
|
|
|
What have you tried? Where are you stuck? What does your code look like right now?
|
|
|
|
|
I didn't start yet because I have no idea to go on with it because the question is asking to design a program that uses nested for
loop statements to display students and their respective locations in a string matrix, and I have never come across such a question.
|
|
|
|
|
Your instructor must have covered the necessary points already, right?
Were you not paying attention?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Quote: Go to ParentI didn't start yet because I have no idea to go on with it because the question is asking to design a program that uses nested for
loop statements to display students and their respective locations in a string matrix, and I have never come across such a question.
We are more than willing to help those that are stuck: but that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.
So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.
If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^] and then read your recent course notes again. When you understand them, read the whole question he set carefully, and think about what he is trying to get you to do. This isn't a complicated exercise - it's very basic stuff he needs you to learn here - so a little thought should get it working.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Hi, folks.
I’m developing an application in C# using Visual Studio. This application has a parent form from which the user can call other forms. My original problem was: if the user has already launched a form and he clicks again in the menu item to launch the same form, the program should only focus on the form. If the form is not on screen, the program should launch it. Another problem is that I have 1 form that is launched with 2 different data sets (different tables in a DB).
I solved this problem this way: I declared 2 variables for the forms and defined 2 routines:
private void M2_SaidaEfetiva_Click(object sender, EventArgs e)
{
if (FormEfetivas == null)
{
FormEfetivas = new Frm_Saida();
FormEfetivas.MdiParent = this;
FormEfetivas.Text = "Saídas Efetivas";
FormEfetivas.Tag = "1";
FormEfetivas.Show();
}
FormEfetivas.Activate();
}
private void M2_SaidaPrevisao_Click(object sender, EventArgs e)
{
if (FormPrevisao == null)
{
FormPrevisao = new Frm_Saida();
FormPrevisao.MdiParent = this;
FormPrevisao.Text = "Previsão de Saídas";
FormPrevisao.Tag = "0";
FormPrevisao.Show();
} Now the problem is: when the user opens one form, then closes it, he cannot reopen it again, because the variables (FormEfetivas and FormPrevisao) are not eliminated when the user closes the form.
What am I forgetting here? Can anybody help me?
Thanks.
|
|
|
|
|
Add a handler to the Form.Closed event when you create the instance, and in the handler set the appropriate variable (for example FormEfetivas to null. The existing code will then generate a new instance when they try next time.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Hi, OriginalGriff.
I didn't follow you. Could you explain better? Or give me an example?
Thanks.
|
|
|
|
|
What part doesn't make sense?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
It's not a matter of making sense. I understand what you wrote, but I'm confused about how to do it.
Could you explain it?
Thanks.
|
|
|
|
|
Explain what? I have no idea which bits you are capable of doing for yourself!
So ... you know how to add an event handler, yes?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
|
Simple enough:
private void M2_SaidaEfetiva_Click(object sender, EventArgs e)
{
var theForm = Application.OpenForms.OfType<Frm_Saida>().FirstOrDefault();
if (theForm is null)
{
theForm = new Frm_Saida();
theForm.MdiParent = this;
theForm.Text = "Saídas Efetivas";
theForm.Tag = "1";
theForm.Show();
}
theForm.Activate();
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi all,
I would appreciate a hand in designing my code.
I have a number of classes for different entities (currently 7 but there can be more in the future). I need a method in each of these classes that authorizes user's access to a file resource. Implementation varies but an exception must be thrown if user does not have access to the file in question.
Problem is, when the file is being accessed, I need to call the authorization method of the correct class based on the data on the file. Files are stored in a db table and one of the fields in that table determines which entity the file is related to and how to find which user has access to the file.
So I must read the file data from db, then see which entity it's related to and then call the authorization method of the correct class.
Is there a way in C# to accomplish this without having to make a switch case structure on the file field value and initialize a class and call a method?
Example of the classes used:
public class FileAttachment
{
protected void AuthorizeFileAccess(FileAttachmentData file)
{
}
}
public class ChatMessage
{
public int SenderUserId;
public int RecipientUserId;
}
|
|
|
|