I need to get results(price) into a label selecting by radiobuttion and checkbox and in the end need to add them up. I need to get all the results in a label.
need to get result in label(cost excl. VAT)
list of radiobutton and checkboxes
To build on what Matt Stannett said, The Calculate method would actually be the Changed event handler for all the Checkboxes and Radiobuttons. Basically, anytime anything is changed, recalculate the value and display it of the label.
I would suggest looking into the CheckBox.CheckedChanged and RadioButton.CheckChanged events then have some sort of Calculate method that sets the Text property of the label.
Related
I have a Combobox with several items (C# Labels because I want to change individual text colors). Within callbacks, when editing some textboxes, I change the color and/or text of the items. When I click on the combobox I see that the items in the list have the correct color/text. However, the color/text changes of the selected item are not directly reflected in the shown combobox text. How can I achieve that?
I tried to set the Text property of the combobox itself: no effect. Also setting the selected item to an empty Label and then set it back to the correct Label has no effect. If I set SelectedIndex to -1 and then back to the correct selected index it works and the shown text is updated, but this triggers the SelectionChanged callback which I do not want. I could first detach the SelectionChanged callback from the combobox and then attach it again, but this is in my opinion very ugly programming.
Maybe I am missing something simple...
Edit
I tried binding, following the suggestion of SLak:
List<Label> labels;
MyComboBox.ItemsSource = labels;
The result is still the same. Suppose index 0 is selected. When I change the corresponding Label:
labels[0].Contents = "new content";
then it is not reflected in the selected text of the combobox. When I click the combobox I can see the new text in the unfolded list, but only when I change the selection and then go back to index 0 the new text is shown by the combobox as the selected item. That synchronization should be autmatically.
In ListView there are 3 option of SelectionMode
1.Single - only one item can be selected.
2.Multiple - you can select muliple items, one after the other.
3.Extended - You can select multiple items and used Ctrl or Shift key.
I'm need to select some items in ListView as text in TextBox.
i.e. press with the left button of mouse, until the mouse is up.
and mark all between items as Selected.
How can I make it?
Thanks
1.Single: SelectionMode="Single"?
2 Mutiple : i think use binding
enter link description here
3
enter link description here
Or You try this line SelectionMode="Muti..."
Firstly, the porpose of this problem is to display listView of TextBlocks for allow use ItemsSource of ListView for display text for several reasone.
behind each textBlock that contains a word, there are in the ViewModel class named Word. that contains the text of the word and property of IsSelected.
I solve this problem, by adding 3 EventSetter event to the ListViewItem,
1.PreviewMouseLeftDown
2.MouseEnter
3.PreviewMouseLeftUp
and adding a flag of IsInSelection, and two object Word that present the control in the view,1.firstSelectionWord, 2.lastSelectionWord.
and, when the first event raise, i update the current control to be Selected.
and set a flag IsInSelection to true. and set firstSelectionWord = lastSelectionWord = current word pressed.
in the MouseEnter event i checked if IsInSelection is true, and them mark also the current control to Selected=true. set the lastSelectionWord = current word pressed.
and call a method that mark all the Word between them as selected.
in the PreviewMouseLeftUp function, i set the IsInSelection = false.
I have a listbox in my winform, when an item in the listbox is selected, a value is placed into a textbox in the same Form. There my many items in my listbox which when selected, i want the text box to be empty so i can pass in the new value. How do i check is if the user has clicked on something other their initial selected item? i get the currently selected item like this below:
var selectedItem = (ReportItems)listbox.selectedItem
You can use the SelectedIndexChanged event on your ListBox . You can create an event handler for this event to determine when the selected index in the ListBox has been changed. This can be useful when you need to display information in other controls based on the current selection in the ListBox. You can use the event handler for this event to load the information in the other controls.
See MSDN documentation: link
You can add a global variable for your ReportItems and call it 'selItem'.
After the user changed the selected Item you check the "new" selectedItem with the 'selItem'-variable.. i don't think that a listbox has a method that can check if the selection has changed from the previous one..
I'm not sure if there is a reason you're not leveraging the SelectionChanged event of the ListBox or not but you should be if you're not. Further, determining if it's different than the initially selected item should be pretty straight forward because you can save the initially selected item in a private variable in your form and compare every time the method handler for SelectionChanged fires.
Other than this, there's not much more I can suggest because your questions isn't terribly clear and there is no code to look at.
My solution was to always clear the textbox first. So as soon as a user selects an item in the listview, rather than populating the textbox straight away, clear the textbox before populating it.
clearText(); is called soon as a listbox item is clicked.
public void clearText()
{
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
textBox5.Clear();
textBox6.Clear();
textBox7.Clear();
textBox8.Clear();
textBox9.Clear();
textBox10.Clear();
textBox11.Clear();
textBox12.Clear();
}
I am trying to determine if the user has selected a row to get the currently selected row. But when the form is initialized it calls the event.
Is there a way to check if the data grid view is being initialized? I thought about setting a flag and using RowPostPaint to set the flag.
Any other ways to ignore the select row event during initialization?
Maybe it helps to check if the DataGridView has the focus:
if (this.dataGridView.Focused)
{
// handle selection ...
}
On form initialization the control shouldn't have the focus but when the user manually changes the row selection it should have the focus.
And maybe you are using the wrong event to determine the row selection. Are you using "RowEnter"? I suggest you use "SelectionChanged" and then access the "SelectedRow" property.
It depends to which event you subscribe, I suppose it's SelectionChanged ?
If so - define some boolean variable (like dgvIsInitialized), set it false by default, then load data into datagridview datasource and - after loading - set it true.
And in SelectionChanged event do similar to this:
if (dgvIsInitialized)
MessageBox.Show("Selection changed");
When I click on a row I should get the value on which the user is clicked
How do I get that?
How about one of these event:
DataGridView.CellClick
DataGridView.CellContentClick
DataGridView.RowEnter
If I have understood you correctly, then you'll want the SelectedIndexChanged event.
If the grid's SelectionMode is set to FullRowSelect or FullHeaderSelect, you can get the selected row(s), using
DataGridView.SelectedRows
Then for each row you can use the Cells property to get the values.
There are a wide variety of ways to get at the underlying data set.