|
Hi all,
I use the following code to select the next control.
private void opdrachtnummerTextBox_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)13)
{
ZakdataDatabase_Insert("Opdrachtnummer", opdrachtnummerTextBox.Text);
SelectNext_control(opdrachtnummerTextBox.Tag.ToString());
}
}
private void SelectNext_control(string t)
{
bool isNextControl = false;
int TagToFind = (int.Parse(t));
do
{
TagToFind++;
foreach (Control c in this.Controls)
{
if ((c.Tag != null)&&(c.Visible=true))
{
if (c.Tag.ToString() == TagToFind.ToString())
{
isNextControl = true;
c.Select();
}
}
}
if (TagToFind > 102) break;
} while (!isNextControl);
}
All controls are tagged with an incremented number.
What to do if the next control is in a groupBox?
Thanks,
Groover.
0200 A9 23
0202 8D 01 80
0205 00
|
|
|
|
|
If it is in a groupbox, then you have to recursively search into each container control - which would also cover panels and so forth.
But why not do it the easy way? Put the next control reference into the tag directly, instead of a number?
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
To put the next control reference into the tag directly, instead of a number cannot be done because e.g the third control can be a listbox and the Visualibility property of other controls an groupBoxes depend on the selection in the listbox or checkboxes.
Can I use the TabIndex instead?
Thanks,
Groover.
0200 A9 23
0202 8D 01 80
0205 00
|
|
|
|
|
Instead of abusing the Tag , how about adding them to a List? No matter where they'd be located, you'd always have a reference.
Alternatively, use the name-property.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
I think we need some basic information here:
1. are all Controls in the GroupBox of the same Type ? If so, what Type ? If they are all the same type, why not just manipulate the TabIndex property, and let the Tab key do the work for you.
2. Have you considered the implications that a GroupBox has no 'TabStop property ? (hint: probably none !). Note that a Panel has a 'TabStop property. Run-time behavior (tabbing between Controls in a GroupBox will work as expected).
3. are Controls added at run-time to this GroupBox ?
Since the last control added will have the highest TabIndex (and assuming TabStop set to 'true, and that it has a 'TabStop propery: what's the problem here.
4 issue of nested-containers as raised by OriginalGriff: if you have properly adjusted the TabIndex: I see no reason for a recursive descent here: tabbing from one Panel to another and, within the second Panel, "into a third Panel:" is no problem.
So, I think to really understand if you have a unique problem here, we need to know much more about your UI structure, and the way you intend use of the Tab key to work.
best, Bill
"If you shoot at mimes, should you use a silencer ?" Stephen Wright
|
|
|
|
|
In the past, I had honestly never really been too great with inheritance and such. I've used interfaces before but never "properly" I guess you would say. So today, in order to grasp the concept a little more, I decided to experiment with it a bit. I created a Class Library with components I can use to create the structure of a "quiz." The project is simply called "QuizLib." Now, the functionality works just as I had planned. But I would like to know if I went about it the correct way:
Interfaces
IQuiz - Quiz interface; contains information about the quiz (title, subtitle, etc.)
* string Title; - The title of the quiz
* string SubTitle; - The subtitle of the quiz
* List<iquestion> Questions; - A collection of questions which are part of the quiz
* void AddQuestion(IQuestion question);
* void RemoveQuestion(IQuestion question);
IQuestion - Question interface; contains information about questions which are part of the quiz (IQuiz)
* string QuestionText; - The text for the question (e.g. Is CodeProject.com the best?!)
* int Points; - The amount of points the question is worth
IAnswer - Answer interface; contains information about an individual answer for an IQuestion
* string AnswerText; - The answer's text (what will be displayed when you render the question with answers - e.g. "Yes", e.g. "No")
* bool IsCorrect; - Is the answer a correct answer (this is only used in Multiple Choice questions and True/False questions)
And then I have 2 classes which implement the IQuestion interface. And I have 2 classes which implement the IAnswer interface.
class MultipleChoiceQuestion : IQuestion ...... class TrueFalseQuestion : IQuestion
class MultipleChoiceAnswer : IAnswer ...... class TrueFalseAnswer : IAnswer
For MultipleChoiceQuestion, there is no limit on how many answers the question can have. The MultipleChoiceQuestion class adds a "HasOneAnswer" field, which determines whether or not only ONE answer can be correct, or if the user must select more than one in order to correctly answer the question. For TrueFalseQuestion, the List<ianswer> field is auto-generated by the class, since "True" and "False" are the only 2 options.
I hope this makes sense to everyone. Haha. I'm just trying to find out if I'm getting the concept fairly well. Or what I may need to do in order to improve in this topic.
Again, it works as expected. I can easily extend the code to support various question and answer types. That seems to be the basic concept. But still, I wanted to ask.
djj55: Nice but may have a permission problem
Pete O'Hanlon: He has my permission to run it.
|
|
|
|
|
Seems silly to split up IQuestion and IAnswer. You're never going to have a MultipleChoiceQuestion paired up to a TrueFalseAnswer for example, so that should be a single object IMO. An IQuestion+Answer type object. Even if you kept your design, I see no way of actually mapping a question to an answer.
|
|
|
|
|
I'd recommend using a generic
List<IQuestion> for the questions instead of a plain old List. That way you don't have to worry about casting the questions to IQuestion, or having someone add something that's not an IQuestion to the list!
|
|
|
|
|
Since IQuiz has methods to add/remove questions, its Questions property should be a get -only IEnumerable of IQuestion objects instead of a List .
I would recommend separating the question/answer definitions (which are reference, read-only data) from a user's responses (which can be modified). Will reply with another post over the weekend.
/ravi
|
|
|
|
|
To add to the previous answers, I would not use an interface for this - I would use an abstract class instead. The reasoning is that some of your logic will be common to all questions/answers in the form of the Questions enumeration (which should be a get only property returning a List<iquestion> as Ravi says) but it should return a copy of the questions list, not the list itself. Using an abstract class allows this to be in the base, an Interface doesn't so you have to rely on the implementor getting this right each time.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
I appreciate all the input. I will be taking this all into consideration as I go. It's just a learning project, nothing I planned to take anywhere. So this will all give me a fair amount of things I can learn in order to improve. Thanks!
djj55: Nice but may have a permission problem
Pete O'Hanlon: He has my permission to run it.
|
|
|
|
|
You're welcome!
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
Hi,
I have a dll class and from here I am calling a form. I am able to send data from the dll class to the form. But how I am going to get data back from the form to the dll class? I wsed the same code but it is not working backward.
frmLogin login = new frmLogin();
login.Type = type;
login.Username = username;
login.Password = password;
login.Group = group;
login.ShowDialog();
Thanks in advance,
Sai
|
|
|
|
|
Why can't you simply reverse the assignments you have?
login.ShowDialog();
username = login.Username;
password = login.Password;
etc....
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Create a property (or several) in the Form and read it back from the instance once ShowDialog returns - it won't until the user closes the form, so read the data at that point.
frmLogin login = new frmLogin();
login.Type = type;
login.Username = username;
login.Password = password;
login.Group = group;
login.ShowDialog();
type = login.Type;
username = login.Username;
password = login.Password;
group = login.Group;
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
What I did....
In Class 1
if (login.ShowDialog()== DialogResult.OK)
{
ans= login.Result;
}
In form 1
public int Result
{
get;
set;
}
Result = value;
this.DialogResult = DialogResult.OK;
Thnks a lot all,
Sai
|
|
|
|
|
That'll do it!
Nice one - well done.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
I can't make any connection between the code you show here, and any other post on this thread:
This code is not going to compile:
1. the variable 'ans is never declared, or used, just assigned to; will not compile.
2. the variable 'value is never declared: Result = value; will not compile.
3. the statement: "this.DialogResult = DialogResult.OK;" makes no sense unless you have a Form1 scoped variable with the name 'DialogResult declared, and, you should not use variable names identical to Operator names since that way lies utter code confusion. And why would you need a Form1 scoped variable of this type in the first place ?
This is a case where posting code-fragments means no meaningful response is possible.
best, Bill
"If you shoot at mimes, should you use a silencer ?" Stephen Wright
|
|
|
|
|
It compiled and worked.
Thanks,
Sai
|
|
|
|
|
I have this XML file
<?xml version="1.0" encoding="utf-8"?>
<Contacts>
<Contact>
<ContactId>0</ContactId>
<Prefix>
</Prefix>
<FirstName>Kevin</FirstName>
<MiddleName>Marois</MiddleName>
<LastName>Brian</LastName>
<Suffix>
</Suffix>
<Birthday>1965-10-11</Birthday>
<Title>Senior Software Engineer</Title>
<Comments>has 25 years of development experience</Comments>
</Contact>
<Contact>
<ContactId>1</ContactId>
<Prefix>Dr.</Prefix>
<FirstName>Henry</FirstName>
<MiddleName>DeCarlo</MiddleName>
<LastName>G</LastName>
<Suffix>III</Suffix>
<Birthday>1965-10-11</Birthday>
<Title>Oral Surgeon</Title>
<Comments>His office is over on 23rd street</Comments>
</Contact>
<Contact>
<ContactId>2</ContactId>
<Prefix>
</Prefix>
<FirstName>Mattew</FirstName>
<MiddleName>Damon</MiddleName>
<LastName>Paige </LastName>
<Suffix>
</Suffix>
<Birthday>1970-10-08</Birthday>
<Title>Actor</Title>
<Comments>Excellent actor</Comments>
</Contact>
</Contacts>
I want to delete a contact using the ContactId. So far I have this:
public void DeleteContact(int ContactId)
{
ensureFileExists();
XmlDocument doc = new XmlDocument();
doc.Load(XMLFile);
var path = "/contacts/contact[ContactId=" + ContactId + "]";
XmlNode node = doc.SelectSingleNode(path);
node.ParentNode.RemoveChild(node);
doc.Save(XMLFile);
}
But the node is coming back null. How do I delete the contact? What's wrong here?
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
Ahem... case sensitivity... ![Java | [Coffee]](https://codeproject.global.ssl.fastly.net/script/Forums/Images/coffee.gif)
|
|
|
|
|
That did it. Thanks
If it's not broken, fix it until it is
|
|
|
|
|
And if that's your actual date of birth, then you're about two months older than me. ![Jig | [Dance]](https://codeproject.global.ssl.fastly.net/script/Forums/Images/jig.gif)
|
|
|
|
|
you catch it quickly so 5+
Thanks
-Amit Gajjar (MinterProject)
|
|
|
|
|
In my software i need to show the property dialog of a file and navigate to a specific tab in that property dialog? please tell me how to acheive this using c#?
or Is it possible to replace the default property dialog with a custom one?
|
|
|
|