在WPF应用程序的datagrid中查找Textbox控件. [英] Finding Textbox control inside datagrid in WPF Application.

查看:87
本文介绍了在WPF应用程序的datagrid中查找Textbox控件.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我没有在datagrid中找到控件的方法


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;
}

推荐答案

^ ]可以为您提供一些您可以使用的代码.
This article[^] could give you some code that you can use.


这篇关于在WPF应用程序的datagrid中查找Textbox控件.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆