I want to select multiple rows on Janus GridEX, but selectedItems property cannot be assigned and it's read only.
however I can select a specific row by GridEX.Row and set the current selected row, but I cant add a row or any thing like that to select multiple row!
Can anyone help me
Thanks alot, Shahin
First make sure that your grid allows selecting multiple rows. This can either be set in the designer or in code.
gridEX1.SelectionMode = SelectionMode.MultipleSelection;
Now to select rows, use SelectedItems.Add(position) where position is the index of the row in the grid.
GridEXRow row1 = ...;
GridEXRow row2 = ...;
gridEX1.SelectedItems.Add(row1.Position);
gridEX1.SelectedItems.Add(row2.Position);
Related
I have a text box search bar in my WPF application that displays records in a datagrid if they match the textbox content. The DataGrid has 2 cells- The first is a string and the second is an Int. I would like to retrieve the int values from the second cell in every row by clicking a separate search button. I unfortunately cannot seem to figure out how to accomplish this.
string ID = (DataGrid.SelectedCells[1].Column.GetCellContent(0) as TextBlock).Text;
About Retrieve The Specific Cell
The way to get the cell by row and colunm info:
https://stackoverflow.com/a/11615729/12949439
You can use the GetCell(int row, int colunm) method which created by #LPL in loops to get all cells in the DataGrid.
After you get all the cells, you can find the specific cell in them, and select it.
About Select The Specific Cell
The DataGrid has a SelectionUnit property, and you can set it into DataGridSelectionUnit.SingleCell then you can just select cell instead of select whole row.
And you can also use the SelectedCells property to get or set the selected cell(s).
And if you want the user can only select one cell, you can set SelectionMode property into DataGridSelectionMode.Single, so the user can not select multi-cells.
And for more infomation, you read the MSDN document about DataGrid, about DataGrid.SelectionUnit, about DataGrid.SelectedCells, and about DataGrid.SelectionMode.
I am new to Infragistics using UltraGrid.
I am trying to select multiple rows using checkbox column (or if there is another idea)
I have a code for DataGridView to select multiple rows and insert it to list, than try to delete or to do code with selected items.
//get the selected item
List<DataGridViewRow> selectedRows = (from row in Detail_shanuDGV.Rows.Cast<DataGridViewRow>()
where Convert.ToBoolean(row.Cells["checkBoxColumn1"].Value) == true
select row).ToList();
But when I try to use this code with UltraGrid like this
List<UltraGrid> selectedRows = (from row in ultraGrid1.Rows.Cast<UltraGrid>()
where Convert.ToBoolean(row.Cells["caption"].Value) == true
select row).ToList();
It gives me this error
'UltraGrid' does not contain a definition for 'Cells' and no extension method 'Cells' accepting a first argument of type 'UltraGrid' could be found
So if theres another idea or how to find solution to solve this error.
By the way I am using hierarchical UltraGrid with checkbox column, in my UltraGrid I have Master/Details data
You should cast to UltraGridRow not to UltraGrid
List<UltraGridRow> selectedRows = (from row in ultraGrid1.Rows.Cast<UltraGridRow>
where Convert.ToBoolean(row.Cells["caption"].Value) == true
select row).ToList();
Also, probably you need another level of filtering on those rows. For example, it is not clear if the checkbox for the column Caption is on the master or in the details pane of the grid. Also if you have a GroupBy display option then you need to add also another condition to filter only the required rows
For example, suppose that you want to apply this logic but only the rows that are in the details pane. In Infragistcs terms this second pane is called Band and every row has a property for the Band to which it belongs. And the Band has a property Index, so you get
List<UltraGridRow> selectedRows = (from row in ultraGrid1.Rows.Cast<UltraGridRow>
where row.Band.Index == 1 &&
Convert.ToBoolean(row.Cells["caption"].Value) == true
select row).ToList();
Notice that you first check for the Band index and only if this row is on second band you check for the cell value (Because If there is no "caption" column in the first band you get an NRE)
I would like to insert a new DataGridViewRow into my DataGridView at a specific index. If I just create a new Row like
DataGridViewRow dgwr = new DataGridViewRow();
datagridview1.Rows.Insert(index, dgwr);
I will not get the "settings" of the DataGridView, like for example my "Cells" will be 0. This does not happen if I use.
DataGridView1.Add();
But then again, then I cant chose where in the list I would like my post...
Is there anyway to combine these advantages?
/Nick
grid.Rows.Insert(index, 1);
var addedRow = grid.Rows[index];
This inserts 1 empty templated row at 'index', and then simply accesses row in 'index'.
The 2nd line is for accessing the just-now-added row.
Can also shorten if you know your wished row values with:
grid.Rows.Insert(index, FirstName, LastName, BirthDate, Etc);
Just have to make sure it is synced with the columns order in the grid, and it makes the row automatically with these fields.
DataGridView and DataGridRowView are just visual representations of your data source and one row in your data source. A new visual row should be displayed in your DataView after a new row is added to your data source.
If you want to get the view row when new row is added handle RowsAdded event.
well i have worked with datagridview now i need to work with a listview i dont know how to select the value it has in one cell..
my another option is when a cell was added or deleted, all this information is on datagridview
but it doesn't have a (datasourcechanged) then how can i anyone of these?
I tried secund with this code:
DataGridView1.DataSource = lvDevices
so i could select anyone but i need when in datagrid changed its value, it passed to datagridview well my another way is
how can i select the value of one cell in a ListView?
you could try this in this listview1_doubleclick event. ...
string a = listView1.SelectedItems[0].SubItems[column index corresponding selected cell].Text.
I am brand spanking new to LINQ and am trying to use it in my current hobby project. I have a datagridview where the first cell of each row is a datagridviewcheckbox, and the 4th cell is a string.
If the checkbox is checked, I need to add the 4th cell's value to a list.
At first I tried:
var selectedID = from c in multiContactLookup.SelectedCells.Cast<DataGridViewCell>()
select multiContactLookup.Rows[c.RowIndex].Cells[4].Value;
That didn't work because the checked cells are programatically unselected so c is never a value.
Then I tried:
var sel2 = from r in multiContactLookup.Rows.Cast<DataGridViewRow>()
where r.Cells[0].Value is true select r.Cells[4].Value;
but somehow my syntax is wrong.
Using LINQ, how can I select the rows where the first cell is checked then select the value of the first cell? Do I have to split this into two collections?
Thank you!
I think this should work:
IEnumerable<string> values = multiContactLookup.Rows.Cast<DataGridViewRow>()
.Where(row => (bool)row.Cells[0].Value)
.Select(row => (string)row.Cells[3].Value);
Maybe not the answer you have been looking for, but...
DataGridView (as most win-forms controls) is not the best source to start with LINQ. Most collections do not implement the correct IEnumerable<T> interface. That's the reason why you need the Cast() workaround.
In general, try to move your applications behavior away from controls and into the data. Maybe your grid is connected to a DataTable. In this case register the DataTable's events for changed data and work with the values of the DataRow, instead of the DataGridViewRow and its cells.