|
|
You're welcome and good luck
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Why on earth are you adding items to a combo box in a method that is named Getsomething and the method doesn't return anything?
Your GetcobBox method is also naive. It will only look in top-level controls on a form. If they are in containers, such as a Panel or GroupBox, they won't be found.
You've got a lot of learning to do. You're creating a ComboBox control in your GetcboBox method, then throwing it away. You're also not using a logical AND operator in your if statement, you're using a binary AND operator (&).
Your GetcboBox method should be something more like this:
private ComboBox GetComboBoxByName(string name)
{
foreach (Control control in this.Controls)
{
if (control is ComboBox && control.Name == name)
{
return control;
}
if (control.HasChildren)
{
return GetComboBoxByName(name);
}
}
return null;
}
But, there's an even easier way to do it by having the .NET Framework do the work for you. Since you can't have two controls on the form with the exact same name, this will either return the control you're looking for, return null, or throw an exception because the control that was found isn't a ComboBox:
private ComboBox GetComboBoxByName(string name)
{
Control[] candidates = this.Controls.Find(name, true);
return (ComboBox)candidates.FirstOrDefault();
}
Keep in mind, this is an example and is not meant to by used in a production application.
System.ItDidntWorkException: Something didn't work as expected.
C# - How to debug code[ ^].
Seriously, go read these articles.
Dave Kreskowiak
|
|
|
|
|
Thanks David!
I'm just started programming in C# so indeed I have to learn a lot.
These answers help me.
Best regards,
J.Dunnewijk
|
|
|
|
|
I have a reportviewer with a column have only two value is BA & FA but when i filter this column by like or = function, it couldn't active, change < or > it will active. when tried with other column,it also active.
Please help me fix this problem, i need filter with that column with like, = function.
i used dataparameter to create expression with these functions.
|
|
|
|
|
|
timer.start and timer.stop is not supported in windows ce
|
|
|
|
|
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
|
Read the following from the CP daily news about C# nullable reference types.
Introducing Nullable Reference Types in C# | .NET Blog[^]
I have got to say that this is one of the best new language features that I have seen in a long time. Last I can recall specifically that I liked was generics in Java - like them but didn't care much for the hacked implementation required to make them 'fit' in java.
But, at least based on this description for the feature above in C#, I like the idea and how they are going to implement it.
|
|
|
|
|
Since we were talking about patterns in another thread, I assume you're familiar with the Null object pattern - Wikipedia[^]?
Funny article BTW; I did not expect that a "null reference" needed to be implemented as a feature.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I believe I looked at that long ago.
C++ api libraries (standard) have a similar class called auto_ptr. I tried it and didn't find it particularly useful. Probably due to the complexity of usage in some cases. Perhaps the same reason that it is now deprecate in C++ (but to be clear I cannot remember why I didn't like it.)
|
|
|
|
|
I would not call the example C# code complex.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Eddy Vluggen wrote: I would not call the example C# code complex.
Ok, but not sure how that is relevant to what I said about auto_ptr (which is not only used for that.)
|
|
|
|
|
It's not, just like talking about C++ in a C# forum isn't
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I am trying to create a C# widows form application that allows people to attend a group and sign up to one of the days they have. I would like the users to be able to sign in inputting their name, organisation, group and then using an automated time, to sign out. This data should then be copied to a database or file. they should then sign out later choosing their name from a drop down menu and again clicking a box so to get another automated time in which they will be able to sign out. The timein and timeout will be used to create a retention time in which the admin can access a page that displays this in a bar chart. There should be an option to register users to a group or create a group on the admin page.
|
|
|
|
|
..and your question is...?
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
And?
What have you tried?
Where are you stuck?
What help do you need?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I have tried searching for tutorials and need help being pointed in the right direction.
I am stuck with trying to get the local database to accept data and ensuring my SQL commands are safe. I would also like help for what you would do if creating this application.
|
|
|
|
|
That doesn't tell us what you have tried: we have no idea what stage you have got to.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Please help. How to put two columns in a combo box (list Box, text box:mad. I work with VS2015, c# and MySql 5.7.
Attached part of the code.
private void comboBox1_Click (object sender, EventArgs e)
{
MySqlConnection conn;
myConnectionString = pwput;
conn = new MySql.Data.MySqlClient.MySqlConnection ();
conn.ConnectionString = myConnectionString;
try
{
conn.Open ();
}
catch (MySqlException ex)
{
switch (ex.Number)
{
case 0:
MessageBox.Show ("DO NOT SUCCE TO CONNECT ON SERVER, CLOSE PROGRAM TO TAKE A REPLY");
Close ();
break;
case 1042:
MessageBox.Show ("NOT ACTIVE SERVER, SUBSCRIBE SERVER PA REPEAT CONNECTING");
Close ();
break;
}
conn.Close ();
}
if (conn.State! = ConnectionState.Open)
{
MessageBox.Show ("DO NOT SUCCE TO CONNECT ON SERVER \ r \ n CLOSE PROGRAM TO TAKE READY \ r \ n");
}
else
{
AutoCompleteStringCollection kontoopis = new AutoCompleteStringCollection ();
string wnadidok = "SELECT idkonto, FROM account name";
loadingData = false;
DataTable dtkon = new DataTable ();
dtkon.Columns.Add ();
dtkon.Columns.Add ();
MySqlDataAdapter mdkon = new MySqlDataAdapter (wnadidok, conn);
mdkon.Fill (dtkon);
loadingData = true;
comboBox1.DataSource = dtkon;
// which field is shown in the table below
comboBox1.DisplayMember = "idkonto";
comboBox1.ValueMember = "idkonto";
comboBox1.DisplayMember = "title";
comboBox1.ValueMember = "title";
comboBox1.SelectedIndex = -1;
comboBox1.Text = "";
loadingData = false;
}
conn.Close ();
}
Thank you
|
|
|
|
|
|
|
your select query doesnt contans "title " but you have mapped the title to value member
the below lines repeating twice, however the compiler will takes only the latest assigned values
comboBox1.DisplayMember = "idkonto";
comboBox1.ValueMember = "idkonto";
comboBox1.DisplayMember = "title";
comboBox1.ValueMember = "title";
try concatenating the two columns in the select query as
string wnadidok = "SELECT idkonto + ' ' + title as combinedCol , title FROM [account name]";
and change the DisplayMember and ValueMember as
comboBox1.DisplayMember = "combinedCol";
comboBox1.ValueMember = "title";
|
|
|
|
|