The Student Room Group

C# Programming: Windows Form

I want to use an if statement for textbox suggesting student name depending on the course selected. Additionally, without using database. It needs to be complete coding and not through using database.

Any ideas would be very helpful!
Reply 2


Hi there!

I already had a look at that but its of no use...

Thank you!
Original post by Mukt96
Hi there!

I already had a look at that but its of no use...

Thank you!


Could you describe what exactly you're trying to do and why that page doesn't help you? otherwise nobody will know what it is that you're trying to do or what the problem is
Reply 4
Original post by winterscoming
Could you describe what exactly you're trying to do and why that page doesn't help you? otherwise nobody will know what it is that you're trying to do or what the problem is


So basically, I have created a form which need to store certain number of student, course details they are enrolled in, modules, start date...

Student:
this will have name of student, student ID, address, passed modules

Course:
Individual course modules, start date, student enrolled, location

So now all i need is
e.g. if course is C0004 then it will update text box suggestion depending on all the learners enrolled in that course...
Depending on what course it is, text box suggestion for student name will keep changing (updating)!
Original post by Mukt96
So basically, I have created a form which need to store certain number of student, course details they are enrolled in, modules, start date...

Student:
this will have name of student, student ID, address, passed modules

Course:
Individual course modules, start date, student enrolled, location

So now all i need is
e.g. if course is C0004 then it will update text box suggestion depending on all the learners enrolled in that course...
Depending on what course it is, text box suggestion for student name will keep changing (updating)!

That sounds very much like something which the
TextBox.AutoCompleteMode from the link above can help you with.

Did you see the example at the bottom of that page and try it in your project? That should be enough information to enable it on the TextBox in your code. Is there anything about the autocomplete which works differently to the way you expect?


Their example on the page shows a property called AutoCompleteCustomSource - You can change its content at any time to add more suggestions - so if you have a method which is called each time your course dropdown changes and you want the autocomplete to use a different list, use AutoCompleteCustomSource.AddRange to add more for autocomplete.

When you want to change the autocomplete suggestions, you should also use AutoCompleteCustomSource.Clear() to remove the previous ones before adding new ones, otherwise you'll have both in the list.

Quick example:
var suggestions = new[] { "" };
if (string.Equals(comboBox1.SelectedItem, "A"))
{
suggestions = new[] { "Aardvark", "Albatross", "Alligator", "Alpaca" };
}
else if (string.Equals(comboBox1.SelectedItem, "B"))
{
suggestions = new[] { "Baboon", "Bat", "Badger", "Bear", "Buffalo" };
}
textBox1.AutoCompleteCustomSource.Clear();
textBox1.AutoCompleteCustomSource.AddRange(suggestions);


Is this what you're trying to do?
(edited 6 years ago)
Reply 6
Original post by winterscoming
That sounds very much like something which the
TextBox.AutoCompleteMode from the link above can help you with.

Did you see the example at the bottom of that page and try it in your project? That should be enough information to enable it on the TextBox in your code. Is there anything about the autocomplete which works differently to the way you expect?


Their example on the page shows a property called AutoCompleteCustomSource - You can change its content at any time to add more suggestions - so if you have a method which is called each time your course dropdown changes and you want the autocomplete to use a different list, use AutoCompleteCustomSource.AddRange to add more for autocomplete.

When you want to change the autocomplete suggestions, you should also use AutoCompleteCustomSource.Clear() to remove the previous ones before adding new ones, otherwise you'll have both in the list.

Quick example:



var suggestions = new[] { "" };
if (string.Equals(comboBox1.SelectedItem, "A":wink:)
{
suggestions = new []
{
"Aardvark", "Albatross", "Alligator", "Alpaca"
};
}
else if (string.Equals(comboBox1.SelectedItem, "B":wink:)
{
suggestions = new[]
{
"Baboon", "Bat", "Badger", "Bear", "Buffalo"
};
}
textBox1.AutoCompleteCustomSource.Clear();
textBox1.AutoCompleteCustomSource.AddRange(suggestions);





Is this what you're trying to do?


I think this should do my work!

Thank you. Really appreciate it!!! :smile:

Quick Reply

Latest

Trending

Trending