|
You have described at least 2 class requirements. Your character will have single item attributes (name, job title, motivation) and a collection of multiple attributes (descriptive traits and personality traits. So for the single attributes you have a field and for the multiple attributes you need a List<attributes> collection.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I'd like to add to the useful answer Mycroft gave you ...
To me your question suggests you are new to object-oriented programming ... nothing wrong with that ! Everybody here was "new" ... once
It's important you get a clear understanding of what the fundamental elements of .NET OOP are: Classes, Abstract Classes, Structs, Interfaces, Inheritance.
The best way to do this, imho, is to get a good book and study it carefully. Here are recommendations I have made that people have found useful:
[^], [^].
Some disciplined study ... and lots of experimentation ... will have a great value for you in the near future.
«While I complain of being able to see only a shadow of the past, I may be insensitive to reality as it is now, since I'm not at a stage of development where I'm capable of seeing it.» Claude Levi-Strauss (Tristes Tropiques, 1955)
|
|
|
|
|
Ignore this specific example, and think more generally: how would you do this in the "real world"?
What information is there that is "single use" and associated with one individual? What information is shared by multiple individuals? And what information is multiply associated with a single individual?
Think about cars for a moment.
"Your car" is a specific vehicle: it has a unique registration, VIN number. But it shares it's manufacturer with many other vehicles, it's model with a large number of those, it's colour with a range of vehicles from other manufacturers, and it has a number of optional features associated with that specific vehicle.
So you have "single use" info: registration, VIN, owner.
"shared" info: manufacturer, model, colour.
"multiple" info: reversing camera, GPS system, leather interior.
So a Car class would need to have a way to contain that:
public class Car
{
public string Registration { get; set; }
public string VIN { get; set; }
public Manufacturer Manufacturer { get; set; }
public Model Model { get; set; }
public Color Color { get; set; }
public List<Option> Options { get; set; }
}
Your problem is the same thing: analyze the data you need to handle, and work out how you need to store it. With a bit of thinking, it should be pretty obvious what you need to do - so try it with several examples, and refine your model until it works with everything you can think of.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Hi,
i need help.
How to when select item from listview from Form1 and click button, to open it Form2 and focus that item to combobox.
Thank you in advance !
|
|
|
|
|
Why do you have a ListView and a ComboBox if they both contain the same items?
What's the point of switching forms if it's the same data? And the same "selected item"?
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
In first Form are just name of users in listview, and in the other Form2 are all data from user(name, age ...) .
Witch code to get that select item form listview from Form1 switch to Form2 and focus in combobox.
|
|
|
|
|
You have 2 "challenges":
1) Passing data between forms
2) And initializing a combobox.
And since all can be done in any number of ways, there is no easy answer.
For (1), it sounds like form1 creates form2, so pass the "selected name" to form2 in form2's constructor. Form1's "selection" is the .SelectedItem / item at .SelectedIndex in the listview.
In (2), initialize the combobox to the item with the "selected name" by locating it's index in the cb's itemsource; and set the .SelectedIndex to that.
(As I said, there are other ways; but you got to start somewhere).
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Something doesn't work.
This is database table:
CREATE TABLE [dbo].[Klijent] (
[klijentId] INT IDENTITY (1, 1) NOT NULL,
[naziv_klijenta] VARCHAR (50) NOT NULL,
[telefon] CHAR (15) NOT NULL,
PRIMARY KEY CLUSTERED ([klijentId] ASC)
);
Code Form1:
private void buttonPrikazi_Click(object sender, RoutedEventArgs e)
{
PostojeciKorisnik korisnik = new PostojeciKorisnik();
korisnik.itemForm1 = listViewPregled.SelectedItem.ToString();
korisnik.Show();
}
Code Form2:
public string itemForm1;
public PostojeciKorisnik(string item)
{
InitializeComponent();
this.itemForm1 = item;
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
comboBoxKlijent.Items.Add(itemForm1);
}
|
|
|
|
|
Even with this little code, there's a lot going on. First, just get the "selected item".
The "selected item" depends on the "selected index".
if the selected index is not > -1, the selected item will be null. You need code to handle that.
Then you need to decide how you want to get the "name" to form 2.
You have a constructor, which you ignored; and set the property directyly instead. Works, but "why"?
Your combo box should already be loaded; you're just doing a "lookup"; and setting the selected index on the combo box.
Methinks you should have a better plan; a flow chart perhaps.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Assuming you actually want to pass the selected item from form 1 to form 2 you do this in the click event of the button.
Try this Search
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Yes, which code can this item from Form1 switch to Form2 and focus in combobox.
|
|
|
|
|
Did you even look at the results of the search? The article there will tell you how to achieve what you are hoping to do.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I set myself "coding challenges:" this is one of them.
The questions: how to "stop" the recursion without using an external boolean flag. Context: while I know how to write hierarchy-enumeration code using a Stack, for TreeViews and such, the "path-finding" problem, here, is running down the walls of my brain like warm honey .. the code works, but it don't feel right. A bigger issue may be if the strategy I used to try and optimize the search ... via keeping track of "visited" values ... is accurate, robust, etc.
Using a generic Dictionary<T1, List<T1>> RDictT1T2; named 'test5 ... with these sample values:
var test5 = new Dictionary<string. List<string>>>();
test5.Add("a", new List<string>{"c", "d", "b" });
test5.Add("b", new List<string> { "c","f","g", "e" });
test5.Add("e", new List<string> { "g", "h", "k" });
test5.Add("k", new List<string> { "b", "l",}); I use the following code to get a possible "path" between one string value and another:
private List<T1> Result, Visited;
private T1 Start, Target;
private bool found = false;
public List<T1> FindPath(T1 start, T1 target)
{
Result = new List<T1>();
Visited = new List<T1>();
Start = start;
if (RDictT1T2[Start].Count == 0) return null;
Target = target;
Visited.Add(Start);
Result.Add(Start);
if (RDictT1T2.ContainsKey(Start) && RDictT1T2[Start].Contains(Target))
{
Result.Add(Target);
return Result;
}
found = false;
return FindRecurse(Start);
}
private List<T1> FindRecurse(T1 rstart)
{
foreach (var t1 in RDictT1T2[rstart])
{
if (Visited.Contains(t1))
{
continue;
}
else
{
if(
!RDictT1T2.ContainsKey(t1)
||
RDictT1T2[t1].Count == 0
)
{
Visited.Add(t1);
continue;
}
}
Result.Add(t1);
Visited.Add(t1);
if (RDictT1T2[t1].Contains(Target))
{
Result.Add(Target);
found = true;
}
else
{
FindRecurse(t1);
}
}
return found ? Result : null;
} These tests produce the expected results:
var r1 = test5.FindPath("a", "d");
var r2 = test5.FindPath("a", "f");
var r3 = test5.FindPath("a", "k");
var r4 = test5.FindPath("k", "x");
var r5 = test5.FindPath("k", "g");
«While I complain of being able to see only a shadow of the past, I may be insensitive to reality as it is now, since I'm not at a stage of development where I'm capable of seeing it.» Claude Levi-Strauss (Tristes Tropiques, 1955)
|
|
|
|
|
I would have taken it one step further ... and built the actual "object graph"; which would be easier to traverse than probing a dictionary.
I use producedural code to build object graphs that can then be accessed "functionally" at run time.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Gerry Schmitz wrote: I use producedural code to build object graphs that can then be accessed "functionally" at run time. I do too; it would be great to see an example of your code.
«While I complain of being able to see only a shadow of the past, I may be insensitive to reality as it is now, since I'm not at a stage of development where I'm capable of seeing it.» Claude Levi-Strauss (Tristes Tropiques, 1955)
|
|
|
|
|
Message Closed
modified 5-Jan-18 2:47am.
|
|
|
|
|
Message Closed
modified 15-Jan-18 13:17pm.
|
|
|
|
|
Sorry ... I thought it was a tree.
And sorry for boring you.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Something like this seems to work:
public static IReadOnlyCollection<T> FindPath<T>(this IReadOnlyDictionary<T, IReadOnlyCollection<T>> nodes, T start, T target, IEqualityComparer<T> comparer = null)
{
if (nodes == null) throw new ArgumentNullException(nameof(nodes));
if (comparer == null) comparer = EqualityComparer<T>.Default;
var prefix = new List<T> { start };
return FindPathCore(start, prefix);
IReadOnlyCollection<T> FindPathCore(T current, IReadOnlyCollection<T> pathToCurrent)
{
if (comparer.Equals(current, target))
{
return pathToCurrent;
}
if (nodes.TryGetValue(current, out var connections))
{
foreach (T node in connections.Except(pathToCurrent))
{
var path = new List<T>(pathToCurrent);
path.Add(node);
var result = FindPathCore(node, path);
if (result != null) return result;
}
}
return null;
}
} Test:
var test5 = new Dictionary<string, IReadOnlyCollection<string>>
{
["a"] = new List<string> { "c", "d", "b" },
["b"] = new List<string> { "c", "f", "g", "e" },
["e"] = new List<string> { "g", "h", "k" },
["k"] = new List<string> { "b", "l" },
};
test5.FindPath("a", "d").Dump();
test5.FindPath("a", "f").Dump();
test5.FindPath("a", "k").Dump();
test5.FindPath("k", "x").Dump();
test5.FindPath("k", "g").Dump();
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
@RichardDeeming
Thanks, Richard; I don't know how I missed seeing this post until now, but I look forward to studying your code !
cheers, Bill
«... thank the gods that they have made you superior to those events which they have not placed within your own control, rendered you accountable for that only which is within you own control For what, then, have they made you responsible? For that which is alone in your own power—a right use of things as they appear.» Discourses of Epictetus Book I:12
|
|
|
|
|
I'm developing an app on multiple PC's. Sometimes at the office, sometimes at home.
I keep having to go into the App.Config and commenting/uncommenting connection strings to point to the PC that I'm on that day.
Is there a better way to do this?
Thanks
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
|
The SQL instance names are different on each PC, so I have different connection strings
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
That's what I use it for: different connections strings for my Desktop and the WookieTab. Change in one place on each machine (when necessary, I did it when I changed the PC name for the desktop and found out how many different little apps I had accessing SQL the hard way) and it changes in all apps on that machine.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
If it's SQL server on your home machine, you can set up an alias so that when it sees the instance name used at work, it actually points to your local instance. You can therefore use the same connection string on both machines.
You set this up using SQL configuration manager
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================
|
|
|
|
|