string message = ""; POSLibrary.Entity.Supplier supplier = new POSLibrary.Entity.Supplier(); POSLibrary.Entity.SupplierList supplierlist = new POSLibrary.Entity.SupplierList(); supplierlist.SupplierID = SupplierID; string msg=""; DataTable dtSupplierItemsList = new DataTable(); var retValue = suppliers.SearchSupplierList(supplierlist, out msg, out dtSupplierItemsList); var itemsSource = grdItems.ItemsSource as IEnumerable; if (grdItems.Items.Count > 0) { for (int i = 0; i < grdItems.SelectedItems.Count; i++) { System.Data.DataRowView row = (System.Data.DataRowView)grdItems.SelectedItems[i]; int itemID = Convert.ToInt16(row.Row.ItemArray[0].ToString()); int supplierID = SupplierID; if (retValue) { int dtsupplierID = 0; int dtitemID = 0; for (int j = 0; j <\; dtSupplierItemsList.Rows.Count; j++) { dtitemID = Convert.ToInt16(dtSupplierItemsList.Rows[j].ItemArray[1].ToString()); dtsupplierID = Convert.ToInt16(dtSupplierItemsList.Rows[j].ItemArray[2].ToString()); if (itemID == dtitemID && supplierID == dtsupplierID) { object o = grdItems.Items; DataGridRow lvi = (DataGridRow)grdItems.ItemContainerGenerator.ContainerFromItem(o); TextBox txtcost = FindByName("txtcost", lvi) as TextBox; //here lvi is coming null and i have to find this textbox string cost = dtSupplierItemsList.Rows[j].ItemArray[4].ToString(); string minimumOrder = dtSupplierItemsList.Rows[j].ItemArray[3].ToString(); } } } } } here the calling function private FrameworkElement FindByName(string name, FrameworkElement root) { Stack<FrameworkElement> tree = new Stack<FrameworkElement>(); tree.Push(root); while (tree.Count > 0) { FrameworkElement current = tree.Pop(); // root is null if (current.Name == name) return current; int count = VisualTreeHelper.GetChildrenCount(current); for (int SupplierCounter = 0; SupplierCounter < count; ++SupplierCounter) { DependencyObject child = VisualTreeHelper.GetChild(current, SupplierCounter); if (child is FrameworkElement) tree.Push((FrameworkElement)child); } } return null; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)