I have a listbox and a grid (5 row,1 column), may be each grid row has a canvas. When I drag an item from the listbox and drag into a row in the grid, this row will change color. How can I do it? If I want to change this row and the next row at the same time, is it possible?
Thanks!
Have a look at these articles -
http://www.codeproject.com/Articles/17266/Drag-and-Drop-Items-in-a-WPF-ListView
http://www.codeproject.com/Articles/22855/ListBox-Drag-Drop-using-Attached-Properties
http://blogs.msdn.com/b/jaimer/archive/2007/07/12/drag-drop-in-wpf-explained-end-to-end.aspx
Related
I have a WinForms DataGrid (not DataGridView). When I manually select a row, the row indicator, shown in the first image below, shows on the selected rows. However, if I set the DataGrid's datasource after a save and programmatically select the second row using:
datagrid.Select(1), the second row gets the highlighted background color but the focus indicator is on the first row as shown in the second image below.
Is there a way to make the selected row get focus and have the indicator display for the row?
Since this is the old System.Windows.Forms.DataGrid, the Row selection method is slightly different than the DataGridView's.
You can select a Row, as you're doing, with the Select() method.
This doesn't change the Current Row. To make a Row the Current, you can use the CurrentRowIndex property.
Combined, these two move the selection and set the Current Row.
// Selects and highlights the Row at index 1
dataGrid.Select(1);
// Make the Row at index 1 the Current
dataGrid.CurrentRowIndex = 1;
Something similar in a DataGridView:
(One of the methods that can be used to achieve this result)
// Move the focus and selects the Row at index 1
dataGridView.Rows[1].Selected = true;
// Make the Row at index 1 the Current setting the CurrentCell property
dataGridView.CurrentCell = dgvTest.Rows[1].Cells[0];
Try this:
dataGridView1.FirstDisplayedScrollingRowIndex =
dataGridView1.Rows[dataGridView1.Rows.Count - 2].Index;
I have a data grid view created with WPF. And i have already set the items source for the grid view. And also i got a text box and a button. When i put the row index to the text box and presses the button that particular row with index should be displayed with some color. I'm new to WPF, so How can i do this?
First you select the row based on its row index by using ContainerFromIndex() method:
DataGridRow row = (DataGridRow)dataGrid.ItemContainerGenerator.ContainerFromIndex(row_index);
Finally set background on row:
row.Background = Brushes.Red;
i have a datagrid with 10 rows. The columns are all of type textbox . But only for the 7th row i want the column template to be combobox instead of textbox. can this be done ?? Any examples ?
I think you can achieve this by having both textbox and combox in the celltemplate and Hide combox for all other rows except 7th row and Hide textbox for 7th row.
Grid supposed to have both 3 RowDefinition and ColumnDefinition (Every cell has no element)
I already accomplished this scenario using UniformGrid.. BUT unfortunately the image sizes are ultimately the same to fill each cell with the ListBox SelectedItems.
Just this: ItemsSource="{Binding ElementName=ListBoxCollection, Path=SelectedItems}"
I try to use Grid to make use of RowSpan and ColumnSpan BUT everytime I select an item on my ListBox it only shows the latest selected item and not filling each cell with selected items like UniformGrid does.
Meaning it shows only 1 image at a time and changes everytime I select another.
All I want is to bind and fill each cell with the ListBox SelectedItems.
Can I accomplish this in XAML?
Or please suggest some control or panel that accomplish the same thing I wanted.
How to get the Row and Column counts of grid in C#, just regular window control grid, not datagrid or gridview
Thanks
Have you tried grid.RowDefinitions.Count and grid.ColumnDefinitions.Count?