How to update 2nd column when enter value in st column wpf - wpf

have Two column First column have " Textbox" , and in 2nd column bind qty column by using DataMemberBinding="{Binding Path=Qty}".
Now what i need to do ,
if i enter 40 in column 1st then it will automatically get update in 2nd column.
means any update value in 1st column need to show in 2nd column.
withdout rebind Grid row.

var row = objPosItem.ParentOfType<GridViewRow>();
if (row != null)
{
row.Cells[6].Content = model.FinalPriceForShow.ToString();
row.Cells[6].HorizontalContentAlignment = HorizontalAlignment.Right;
}

Related

Selenium Webdriver - How to select record from grid view

How can I select specific record from grid view using selenium webdriver (JAVA)
Suppose I want to select the highlighted record in this snapshot. How I can do that:
You should systematically break down the grid into sections, loop through each row's cell to find a match using a unique key and then select the row. In this case, the unique key is the Employee Number column.
In Java:
public void selectRow(String expEmpNo) {
// Get the grid
WebElement grid = driver.findElement(By.id("gpUsers"));
// Get all the rows
By locAllRows = By.xpath(".//*[contains(#class,'x-grid3-body')]//*[contains(#class,'x-grid3-row')]");
List<WebElement> allRows = grid.findElements(locAllRows);
// Loop through each row and compare actual emp. no. with expected emp. no.
for(WebElement row : allRows) {
// Emp No. is 4th column
By locEmpNo = By.xpath(".//*[#class='x-grid3-cell-inner x-grid3-col-4']");
// Get the Emp. No.
String actEmpNo = row.findElement(locEmpNo).getText();
// Compare actual vs expected
if(actEmpNo.equals(expEmpNo)) {
row.click(); // Select row
System.out.println("Selected row " + (allRows.indexOf(row) + 1) + " having Emp. No. " + expEmpNo)
break; // exit the for loop
}
}
}
I believe that you need something like this
WebElement element = driver.findElement(By.xpath("use the xpath here"));
Select oSelect = new Select(element);
oSelect.selectByVisibleText("enter the visible text you want to select");

Wrong index after re-ordering datagrid rows

I have a DataTable bound to a DataGridView. When I re-order the rows, the column index of the string I'm looking for gets messed up.
I get the index of the Serial Num column... this works, even after I've moved it.
Dim snIndex As Integer = asset_MasterDataGrid.Columns.[Single](Function(c) c.Header.ToString() = "Serial Num").DisplayIndex
Then I direct cast the row i'm clicking
Dim item As DataRowView = DirectCast(asset_MasterDataGrid.SelectedItem, DataRowView)
Then I grab the string of the cell in the Serial Num column.
Dim sn As String = item.Row(snIndex)
[![enter image description here][1]][1]
[1]: https://i.stack.imgur.com/f4EqC.png
This of course doesn't work, and when I re-order my serial number column to lets say... index 0, it grabs the asset ID cell string. I'm trying to find the Serial number of whatever row I click on, no matter where the serial number column is.
Any ideas on how to correct this issue?
You can access a column of a DataRowView by its name rather than the index:
Dim item As DataRowView = DirectCast(asset_MasterDataGrid.SelectedItem, DataRowView)
Dim sn As String = item("Serial Num")
This should work provided that you know the name of the serial number column.
If you are clicking a datagrid header to reorder your selection, the linked data will not be reordered, the index will still be the same, the selected item will be what you select, but its index in the DataTable has not changed
to seach column index try this (C#)
var index = 0;
for (var i = 0, i < asset_MasterDataGrid.Columns.Count; i++)
if (((DataColumn)asset_MasterDataGrid).ColumnName == "Serial Num")
{
index = i;
break;
}
obvious this is your column with your serial.
Now to get your value with this serial number you need to seach in your DataGrid for it (not in your dataTable)

How to get the selected column count in datagrid

I want selected column's index of the DataGrid. For example, if I select the first column, I want the first column's index (index = 0).
I tried it in the DataGrid SelectionChanged event, but I can't seem to get the particular column index. If any one knows how to do it, help me with some sample code.
The DataGrid.Items property returns a DataGridItemCollection representing the DataGridItems in the DataGrid.
Each DataGridItem is representative of a single row in the rendered table. Also, the DataGridItem exposes a Cells property which represents the no. of tablecells (in other words, the columns) in the rendered table.
// Get the Row Count
int rowCount = myGrid.Items.Count;
// Get the no. of columns in the first row.
int colCount = myGrid.Items[0].Cells.Count;
I am assuming that you want the indexes of any columns that are selected. Here is the code I've come up with:
List<int> selectedColumnIndexes = new List<int>(dataGrid.SelectedCells.Count);
for (int i = 0; i < dataGrid.SelectedCells.Count; i++)
{
foreach (DataGridColumn column in dataGrid.Columns)
{
if (column.DisplayIndex == dataGrid.SelectedCells[i].Column.DisplayIndex)
{
if (!selectedColumnIndexes.Contains(column.DisplayIndex))
{
selectedColumnIndexes.Add(column.DisplayIndex);
}
}
}
}
Thus you will have a list of all the indexes of the columns currently selected. This question gives some nice clues in what direction to head here.
Obviously, if you want just the number of columns actually selected, then that value is simply selectedColumnIndexes.Count after the for loops have run through.

Getting hold of grid cell and clearing all controls in it

I have a grid with two columns and multiple rows, each cell containing a number of controls. Among these controls I have a button which should, when I press it, delete all the controls in the current grid cell. How can I get the index of the grid cell my button is in and how can I delete all controls in this cell?
Does this work for you? you'll need to add a using statement for System.Linq
//get the row and column of the button that was pressed.
var row = (int)myButton.GetValue(Grid.RowProperty);
var col = (int)myButton.GetValue(Grid.ColumnProperty);
//go through each child in the grid.
foreach (var uiElement in myGrid.Children)
{ //if the row and col match, then delete the item.
if (uiElement.GetValue(Grid.ColumnProperty) == col && uiElement.GetValue(Grid.RowProperty) == row)
myGrid.Children.Remove(uiElement);
}
using linq and extending the previous answer, notice the ToList() so you can immediately remove the element
//get the row and column of the button that was pressed.
var row = (int)myButton.GetValue(Grid.RowProperty);
var col = (int)myButton.GetValue(Grid.ColumnProperty);
//go through each child in the grid.
//if the row and col match, then delete the item.
foreach (var uiElement in myGrid.Children.Where(uiElement => (int)uiElement.GetValue(Grid.ColumnProperty) == col && (int)uiElement.GetValue(Grid.RowProperty) == row).ToList())
{
myGrid.Children.Remove(uiElement);
}

How to change the focus from one cell to the another cell on the next row and the same column

I want to change the row selection from one row to next row and the focus from one cell to the another cell on the the same column.
that is, 2nd row is selected in my datagrid and the focus is currently on the 2nd row 3rd column.
when i click a button on my screen, 3rd must get selected and the focus must be on the 3rd row 3rd column.
now if i type something then it must automatically reflect on the 3rd row 3rd column.
Thanks in advance!
Try this little helper method for selecting a cell based on a column and a row item
private static void SelectCell(DataGrid dataGrid, DataGridColumn column, Object rowItem) {
if (rowItem != null) {
//scroll the item into view
dataGrid.ScrollIntoView(rowItem);
dataGrid.ScrollIntoView(rowItem, column);
//get the cell info
DataGridCellInfo cellInfo = new DataGridCellInfo(rowItem, column);
if (dataGrid.CurrentCell.Item == cellInfo.Item && dataGrid.CurrentCell.Column == cellInfo.Column) { }
else {
dataGrid.Focus();
dataGrid.CurrentCell = cellInfo;
//set the cell to be selected
dataGrid.SelectedCells.Clear();
dataGrid.SelectedCells.Add(cellInfo);
}
}
}
The following code will solve the issue.
_dgTemp.CommitEdit();
object SelectedItem = _dgTemp.SelectedItem;
DataGridRow _dgRow = DataGridHelper.GetRow(_dgTemp, _dgTemp.Items.IndexOf(SelectedItem));
DataGridCell _dgCell = DataGridHelper.GetCell(_dgTemp, _dgRow, _dgTemp.Columns.IndexOf(_dgTemp.CurrentColumn));
_dgCell.MoveFocus(new TraversalRequest(FocusNavigationDirection.Down));
_dgTemp.ScrollIntoView(_dgTemp.Items.IndexOf(_dgTemp.CurrentItem));
_dgTemp.UpdateLayout();
_dgTemp.SelectedIndex = _dgTemp.Items.IndexOf(_dgTemp.CurrentItem);

Resources