Dave's answer is the one you should be following. Just for completeness: The reason why Visual Studio shows a squiggly red line under Items is because mycbox is of the type Control and not ComboBox, and as a Control it doesn't have an Items-property. You verified that it actually is a ComboBox but that doesn't "automagically" make the variable mycbox of that type. You would have to cast it to ComboBox before being able to access its Items-property:
If you get squiggly red lines place the mouse cursor on it and Visual Studio will (usually) give you a pretty good hint at what's wrong with it in a popup-tooltip.
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 inthis.Controls)
if (control is ComboBox && control.Name == name)
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:
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.
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!
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.
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 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.
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.
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)
myConnectionString = pwput;
conn = new MySql.Data.MySqlClient.MySqlConnection ();
conn.ConnectionString = myConnectionString;
catch (MySqlException ex)
MessageBox.Show ("DO NOT SUCCE TO CONNECT ON SERVER, CLOSE PROGRAM TO TAKE A REPLY");
MessageBox.Show ("NOT ACTIVE SERVER, SUBSCRIBE SERVER PA REPEAT CONNECTING");
if (conn.State! = ConnectionState.Open)
MessageBox.Show ("DO NOT SUCCE TO CONNECT ON SERVER \ r \ n CLOSE PROGRAM TO TAKE READY \ r \ n");
AutoCompleteStringCollection kontoopis = new AutoCompleteStringCollection ();
string wnadidok = "SELECT idkonto, FROM account name";
loadingData = false;
DataTable dtkon = new DataTable ();
MySqlDataAdapter mdkon = new MySqlDataAdapter (wnadidok, conn);
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;