Click here to Skip to main content
15,922,894 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am not getting how to find control inside datagrid


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;
}
Posted
Updated 1-Apr-11 23:38pm
v8

1 solution

This article[^] could give you some code that you can use.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900