Remove controls on Grid based on Datatable value [closed] - c#

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have a MySQL Datatable with 3 columns : Name, X, Y
Let's say for now there's these values :
Basically I have a timer which loops through this Datatable and adds a new Button with Name, X, Y as it's location.
If I add a new row in my datatable, a new button will be created in the next timer's Tick event. Now how can I implement something to remove a button on the form which is not in the database anymore ?

Remember the list of buttons placed on the form. Then compare the list from the database and the list of buttons placed with Except.
Something like that:
IEnumerable<string> formButtons = ...;
IEnumerable<string> dbButtons = ...;
IEnumerable<string> buttonsToRemove = formButtons.Except(dbButtons);
buttonsToRemove now contains the buttons which are on the form, but not in the database anymore.

Related

How can I delete all the items in combo box? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have a ComboBox control with the DropDownStyle properties set to DropDownList. I want to replace the list of items with some new items at some points in the form but it concatenates the new items with the old items. How can I delete the old items and place new items in the combo box?
I am trying something like that:
this.selectAttribute.Items.AddRange(new object[] {
"Airport_Name", //New items
"City",
"Country"});
You could try clearing the items first:
this.selectAttribute.Items.Clear();
Use the .clear() functionality:
this.selectAttribute.Items.clear()

how to add Buttons in datagrid view using C# .net [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
How to add buttons in DataGridView using WinForms application in c# .NET?
In this picture, you can see that buttons are add in rows for delete, edit and active columns names. Like that way, I want to add buttons in DataGrid view in WinForms.
Right click in your datagridview.
In pop-up select Add Column.
In add column pop-up you can choose DataGridViewButtonColumn.
Just make a function which and call it on form load function
Public void AddButton()
{
//Add button
DataGridViewButtonColumn EditButton = new DataGridViewButtonColumn();
EditButton.UseColumnTextForButtonValue = true;
EditButton.DataPropertyName = "btnColumn";
EditButton.Text = "Button Text";
DataGridView_name.Columns.Add(EditButton);
}
If you want to add it manually from code

How to create images in a Foreach Loop [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have a List of objects and i want to create a Foreach loop which create images on my MainWindow separated by 50 pixels for example. I don't know if I have to create them in the desgner itself or if there's a way to create then place the images the one below the other in a command.
For example i have:
List<string> URIS = new List<string>();
foreach (var i in URIS)
{
//New image in MainWindow with source i
}
Remember that I want a "list" of images in my Window so that every image is below the last one.
Look into the ItemsControl. It has an ItemsSource property that takes a list and lays out its items into a visual list. You can use the ItemTemplate property to control exactly what type of visual is created from each list item, including things like spacing.

Store data to array to pass to second form [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am trying to do the form 1 and form 2:
Form 1: customers click on the radio button , the label will show the price.
I want to store the label price into the class array, so I can serializing the data in order to transfer to form 2 to show the order summary.
Form 2: display the order summary into the textbox
Please help!!!
This has been answered in another question here Passing array between forms and managing in arrays
Here is the answer:
Don't use arrays if you want a data structure that you need to add items to.
Use a generic collection like List.
In your case, a list of integers would be a List.
IList<int> listOfInt = new List<int>();
listOfInt.Add(19);
listOfInt.Add(12);
Form2 frm2 = new Form2();
frm2.TakeThis(listOfInt);
frm2.Show();
When on Form2, your TakeThis function would look like this:
public voidTakeThis(IList<int> listOfInt)
{
listOfInt.Add(34);
}
This will also work when passing the list to another form, as List is a reference type whereas arrays are value types.

How to allow only valid values in a combobox? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
in C# with DotNet 4 i have a form with a combobox which is filled with values when starting the program.
Now user can dropdown and select one of the values.
But: It is also possible to write something new into the combobox-field.
Question: What can i do that it is NOT possible to write something which is not part of the list?
Thanks
To make the text portion of a ComboBox non-editable, set the DropDownStyle property to "DropDownList".
It can be done by simply assigning a property to combobox .DropDownStyle = ComboBoxStyle.DropDownList. but, this property do not allow to edit text. means you have to select item either by mouse or by up/down arrow key. You cannot filter result by selecting this property. if you wish to filter result but don't allow to accept invalid value then you can do this by writing some code in cmb_Validating event
private void cmb_Validating(object sender, CancelEventArgs e)
{
if (cmb.SelectedValue == null && cmb.Text != string.Empty)
e.Cancel=true;
}

Categories