I am using a checkbox on expander. I want, when I check that checkbox ,it will select all rows of list view those are coming under that expander.
set the listview's selectionmode to Multiple' or 'Extended and
on the CheckBox_Checked event you can write the code to select the rows of listview
private void CheckBox_Checked(object sender, RoutedEventArgs e)
{
listview1.SelectAll();
}
Try this inside your checkbox_click events handler:
listView1.BeginUpdate();
foreach (ListViewItem i in listView1.Items)
{
i.Selected = true;
}
listView1.EndUpdate();
Which gives you a bit more flexibility.
Related
I want to insert autocomplete textboxes inside listview control in WPF.
well I downloaded a premade auto complete textbox from nugget called "WpfControls.AutoCompleteTextBox"
here's the code to add it:
private void button_Click_1(object sender, RoutedEventArgs e)
{
WpfControls.AutoCompleteTextBox TestTextBox = new WpfControls.AutoCompleteTextBox();
listView.Items.Add(TestTextBox);
}
Does anyone know how to dynamically set the ElementName for textblock.text binding?
I have two Datagrids that have the same information but the second DataGrid is just a filter of the same datasource, but what I want is to bind text of a textblock to the selected item depending if the item was clicked in the main datagrid or the secondary datagrid.
I have the below code to bind the textblock to one datagrid but I would also like the same to happen if the user clicked an item in the secondDataGrid.
Is this possible?
<TextBlock Margin="29,0" Text="{Binding SelectedItem.Name, ElementName=MainDataGrid}"
It is possible, though I don't think this is the proper solution.
You can handle one of the DataGrids' events in the code-behind, where in the handler you can write the following code:
BindingOperations.SetBinding(textBlock, TextBlock.TextProperty,
new Binding("SelectedItem.Name")
{
ElementName = "DataGrid1"
});
Basically you reset the Binding on the TextBlock's Text property with this code, where:
textBlock is the name of your TextBlock;
with TextBlock.TextProperty you define that you want to work with the Text property on the TextBlock;
The third paramter is the new Binding itself. The constructor takes the Path of the Binding and then in the "body" I set the ElementName.
If DataGrid1 fires the event you set the ElementName to that DataGrid's name, if DataGrid2 fires the event then you set the ElementName to the second DataGrid's name.
SelectionChanged can be a good event to handle on both DataGrid, but if you want the TextBlock to update when you selected and element in the first then select another one in the second and then click back to the first element to update then you need to handle the GotFocus event as well.
Play a little bit with it and you will see what I mean.
My working example:
private void SetBindingOnTextBlock(string elementName)
{
BindingOperations.SetBinding(textBlock, TextBlock.TextProperty, new Binding("SelectedItem.Name")
{
ElementName = elementName
});
}
private void DataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
SetBindingOnTextBlock("DataGrid1");
}
private void DataGrid_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
{
SetBindingOnTextBlock("DataGrid2");
}
private void DataGrid1_GotFocus(object sender, RoutedEventArgs e)
{
SetBindingOnTextBlock("DataGrid1");
}
private void DataGrid2_GotFocus(object sender, RoutedEventArgs e)
{
SetBindingOnTextBlock("DataGrid2");
}
UPDATE 1:
Set
IsSynchronizedWithCurrentItem="True"
on the DataGrids and it may solve your problem if ItemsSources are the same. (Not sure if this is what #dkozl meant) Originally I assumed that they are different.
I have a DataGrid, and in DataGrid are listed users from Database.
I want that , when i click on a member in DataGrid, open a new Window , and show me the members data(Username, Postal code, ... etc what is in the database).
How to open a new window , when i Click on a row?
Solved:
private void dg_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
var windowToOpen = new UsersWindow();
windowToOpen.Show();
}
XAML:
<DataGrid x:Name="NameGrid" MouseLeftButtonDown="dg_MouseLeftButtonDown"/>
Are you using MVVM or doing codebehind?
In any case you should be able to listen on selectedItemChanged and handle it your way
EDIT
Ok. Never tried this by myself..
DataGrid has an SelectedItem property. This gives you the first Row in your selection (If you have Multiselect).
So basically you can do in your Codebehind:
private void Selector_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
var selectedUser = this.theNameOfYourGrid.SelectedItem;
var windowToOpen = new Window();
/*
* Do what you want with your window
*
*
*/
windowToOpen.Show();
}
and in your XAML
<DataGrid SelectionChanged="Selector_OnSelectionChanged" x:Name="theNameOfYourGrid">
</DataGrid>
that should it be
How can we know if a row is dirty in a telerik gridview?
In datagridview we had IsCurrentRowDirty property.
Is there any such property in Telerik?
One way to do this with RadGridView is to use the CellValueChanged event:
void radGridView1_CellValueChanged(object sender, GridViewCellEventArgs e)
{
e.Row.Tag = "ThisRowIsDirty";
}
I'm trying to drag an item from a listbox to a textbox in WPF.
I can't get any code that will let me do this.
Thanks
Use selection change event of listbox
private void listBox2_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
ListBoxItem i = (ListBoxItem)listBox2.Items[listBox2.SelectedIndex];
s = i.Content.ToString();
DragDrop.DoDragDrop(listBox2, i.Content.ToString(), DragDropEffects.All);
}