I have a form with some textboxes and some other items specially combobox.
When I selected an item from combobox that has label "Land" in screenshot, I can't do anything with other elements in form!
that combobox turns blue (means selected and focused) and user cant fill other boxes!
private void cb_land_DropDownClosed(object sender, EventArgs e)
{
foreach (Lands j in lands)
{
if (j.landName.Equals(cb_land.Text))
{
tb_countrykz.Text = j.landKZ;
break;
}
}
}
code for fill combobox from database :
this.länderTableAdapter.Fill(this.test_tab.länder);
I have 3 other combobox in my form and they work fine.
this combobox locks other boxes and does not let user to click on any other elements in form.
Related
I want to be able to edit the items that I have added to my listview.
The listview items were added through a textbox, datetimepicker, and a combobox.
The listview has three columns. What I want is: When I click on the listview item, (the listview selects all the columns) and then click on the edit button, then the textbox is replaced with column one, the datetimepicker is replaced with the date of column 2, and the combobox is replaced with column 3.
Then I can edit the textbox, date, or the combobox items and when I click the save button, then the listview item is updated.
Since you want to use separate edit controls and buttons to update there is no need to overlay the listview subitems with controls.
Here is example code to load the controls from the 1st selected item and to update that Item in the ListView:
private void lv_edit_SelectedIndexChanged(object sender, EventArgs e)
{
if (lv_edit.SelectedIndices.Count > 0)
{
var lvi = lv_edit.SelectedItems[0];
tb_col1.Text = lvi.SubItems[0].Text;
date_col2.Value = Convert.ToDateTime(lvi.SubItems[1].Text);
combo_col3.SelectedIndex = combo_col3.FindStringExact(lvi.SubItems[2].Text);
}
}
private void cb_updateItem_Click(object sender, EventArgs e)
{
if (lv_edit.SelectedIndices.Count > 0)
{
var lvi = lv_edit.SelectedItems[0];
lvi.SubItems[0].Text = tb_col1.Text;
lvi.SubItems[1].Text = date_col2.Value.ToString("dddd, dd. MMMM yyyy");
lvi.SubItems[2].Text = combo_col3.SelectedItem.ToString();
}
}
Note that SubItems[0].Text is the same as Items[0].Text.
Also note that the code assumes that all items have all three fields and their values are all valid, ie that the conversion and the find will work.
I have two views of WPF (Vista1.xaml and Vista2.xaml), and they are part of a MainWindow.xaml.
In the Vista1.xaml i have a listview, where the user selects some items by clicking and the Vista2.xaml has a button.
I want that when the user clicks on the button of Vista2.xaml, get the items that the user previously selected in the listview of Vista1.xaml.
I have class in the Vista1.xaml.cs ListViewItem_PreviewMouseLeftButtonDown method that captures the user selects the item in the listview.
the code is as follows
private void ListViewItem_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
var item = sender as ListViewItem;
if (item != null && item.IsSelected)
{
...
}
}
I appreciate your help
Add a public property to you MainPage that contains the data you want to pass between Vista1 and Vista2. Then, in your event handler of Vista1, set the property and on the button click of Vista2 read the property.
I've got a form that contains a listview which pulls in ticket info from a database. The database objects are all abstracted into a class library. There is a tabpage below the listview which displays various details of the tickets.
My problem is that I've implemented a search at the top of this form which isn't updating that tabpage, only the listview gets updated. After typing in keywords the listview refreshes properly and any items that dont' contain the keywords are removed until the text from the search box is cleared. But I can't get the tabpage to exhibit the same behavior. The tabpage still always contains all tickets.
For example, if I were to search for something where only 1 ticket was returned in the listview and say that ticket was the 10th ticket on record; the tabpage would show me details for the very first ticket. How can I get the tabpage to exhibit the same behavior as my listview after a search is made?
The tabpage currently gets filled with this function:
private void FillTicket()
{
try
{
if (listView1.SelectedIndices.Count > 0)
{
CTicket thistkt = comp.Tickets[listView1.SelectedIndices[0]];
dedit1.DocumentHTML = thistkt.LineItems.GetCombinedProblem();
dedit2.DocumentHTML = thistkt.LineItems.GetCombinedResolution();
lvAssignmentHistory.Items.Clear();
foreach (CInc_AssignmentHistory a in thistkt.AssignmentHistory)
{
ListViewItem itm = new ListViewItem();
itm.Text = a.pAsgn_Datetime.ToString();
itm.SubItems.Add(a.pAsgn_Group_fr);
itm.SubItems.Add(a.pAsgn_from);
itm.SubItems.Add(a.pAsgn_Group_to);
itm.SubItems.Add(a.pAsgn_to);
itm.SubItems.Add(a.pChanged_By);
lvAssignmentHistory.Items.Add(itm);
}
when this is called:
private void listView1_SelectedIndexChanged(object sender, System.EventArgs e)
{
//FillTicket();
if (txtBox_TicketSearch.Text != "")
{
FillTicketNothing();
}
else
{
FillTicket();
}
It seems to me you only update the tab page if the user selects different items in your ListView.
If your listView1_SelectedIndexChanged method is only a handler for the ListView.SelectedIndexChanged event, it is only called when the selection in listView1 changes, not when it's content is changed (without changing selection).
So you should call FillTicket when you changed the content of listView1.Items after your search.
Also, your FillTicket method only updates the tabpage if there are selected items in your ListView:
if (listView1.SelectedIndices.Count > 0)
I don't know if there is an else-branch for that if. If not, there will nothing change on your tab page if no items were selected. You may want to use listView1.Items.Count.
i have 2 listBoxes in a window, one next to the other, with buttons to copy items from one listBox to the other.
when an item from the first listBox is selected the copy button gets enabled, and remove button gets disabled. when i choose an item for the second listBox the copy button gets disabled, and remove button gets enabled.
when you select an item in one of the listBoxes the buttons change with no problem, after the listBox lost focus and you choose the same item that was selected the buttons dont change back.
i understand the problem is that the event of selected item changed will not fire, beacuse the selected item did not change.
setting the selected item to null when the listBox loses focus was not usefull beacuse i need the selcted item. i need to find a way to reselect the selected item when the listBox gains focus, or just fire the even of selected item changed. any suggestions?
You can try the ListBox.LostFocus Event and set the SelectedItem Property to null.
private void ListBox_LostFocus(object sender, RoutedEventArgs e)
{
((ListBox)sender).SelectedItem = null;
}
Use the ListBox.GotFocus event check if there is a SelectedItem, store the index, remove the SelectedItem and use the stored index to reset the SelectedItem. Something like this
private void ListBox_GotFocus(object sender, RoutedEventArgs e)
{
ListBox lb = (ListBox)sender;
if(lb.SelectedItem != null )
{
int index = lb.SelectedIndex;
lb.SelectedItem = null;
lb.SelectedIndex = index;
}
}
i have one combobox and one listview
i want to select item of listbox and click on one clumn of listview multi clumn
then clumn name that i clicked be equal whit item name of listbox
tanks for answer
i want to select one item of listbox,then click on one clumn of listview's clumns,
then this clumn name be equal to selected item in listbox
private void DataValuelst_ColumnClick(object sender, ColumnClickEventArgs e)
{
DataValuelst.Columns[?].Text = Schemacmb.SelectedItem.ToString();
}
the index of clumn that i clicked must be replace whit ?
You can use the SelectedIndex property... So it should be something like this...
private void DataValuelst_ColumnClick(object sender, ColumnClickEventArgs e)
{
DataValuelst.Columns[Schemacmb.SelectedIndex].Text = Schemacmb.SelectedItem.ToString();
}