I have a GridView in c# UWP, that has some items in it (let's say, its filled up with 100 items). I want the GridView to support the arrow-keys on the keyboard. In order to select the item above my current item, I need to know how many items are in one row.
How do I get the number of items in a row?
Related
So I have two list boxes and I want to click on an listbox item and I want the other listbox to correspond and select the same row as well. That way I would select two items in two listbox on the same row with one click. How would I be able to do this?
I have a very large dataset(can be up to 3 million items) that I am retrieving on demand based on the scroll position of a grid. This means that I will never have all the items in one collection. But, I need the grid to be interactive and allow the user to scroll as if all the items were in memory.
So, I need a way to set the amount of rows (data items) so that the scroll bar will be the proper size for my database collection. I know the total number of items in the database, so I just need to set the total number of rows in the grid to match that number.
Is there a simple way to do this in WPF with a Datagrid or GridView?
Edit: The important thing is that the scroll bar is properly sized. That way the collection can be indexed based off of it.
Use event handlers for several button controls to make buttons: Next, Previous, First, Last. Parameterise the SQL called by these buttons with firstrow and lastrow inputs say 1 to 10. Each time Next is called, the SQL will spit out the next 10 rows. The rows on the grid per page will be equal to 10 in this case.
I have a problem with GridViewComboBox column. For each row in GridViewComboBox has different items. When I select an item in first row of GridViewComboBox the items are displayed under the GridViewComboBox correctly but for the second time the the items are displayed at some other place of windows form and not in the GridView.
Any idea why this is happening?
I'm using a WPF datagrid in which multiple records can be selected & it can be sorted (by clicking the column headers).
I want to be able to retain the selected rows after the sort.
Please note I can retain the selected row, the problem arises when the rows to retain are more than 1.
Say for example: I select rows with indices 2 & 3, and then sort on a particular column. After the sort functionality I want to be able to retain the selected rows (old indices-2,3) & new indices - 4,5. Thus, after sorting, the 4th & 5th rows must be selected.
The items source for my datagrid is of type ListCollectionView to which I'm adding sort descriptions when reqd to sort.
Things I have tried:
Tried setting the SelectedItems property. Doesn't work since it is a Read Only property.
Tried setting the IsSelected property of the DataGridRow(s), doesn't work. Though I can see the IsSelected property for the selected rows is set to true, on the screen I do not see the records highlighted.
This one may be vague but I set the selected Index multiple times but this only highlights the record for the last selected index.
Each time after sorting, the last selected record is highlighted. Is there a way by which I can retain the selected rows?
EDIT:
I'm now able to set the selected items of the datagrid using Datagrid.SelectedItems.Add(dataGridRow) or setting the IsSelected property on the datagrid row.
The issue is though the selected items are present, they are not highlighted on the screen. How can I get the rows to be highlighted?
For ex: If 3 records were selected & highlighted before sort, after sort, all records are selected (put breakpoints & checked in Code) but only one record is highlighted.
One may set the selected items of a datagrid by setting the IsSelected property of the row to true.
Or use the SelectedItems.Add() method to add selected items.
I was doing the same but still couldn't see the selected items since, there was another place in the code where the selected items were being modified.
The above solution is tested & works.
How to count the number of selected rows in a DataGridView?
Let's say I highlighted 5 rows, how can I show it in message box?
Please help I'm using WinForms in C#!
you need to set YourGridView.MultiSelect=true; MultiSelect
When the MultiSelect property is set to true, multiple elements (cells, rows, or columns) can be selected in the DataGridView control. To select multiple elements, the user can hold down the CTRL key while clicking the elements to select. Consecutive elements can be selected by clicking the first element to select and then, while holding down the SHIFT key, clicking the last element to select.
then you can use SelectRows.Count property SelectedRows
MessageBox.Show(yourDataGridView.SelectedRows.Count.ToString());
In VB.NET you can use a Lambda expression. Should be easy to translate to C:
SelectedRowCount = DataGridView1.SelectedCells.OfType(Of DataGridViewCell)().Select(Function(x) x.RowIndex).Distinct().Count()