当我扫描当前行本身的条形码时,如何为当前行指定值 [英] How to assign values to current row when I scan barcode in the current row itself

查看:73
本文介绍了当我扫描当前行本身的条形码时,如何为当前行指定值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个wpf数据网格,我创建了一个新行,我在第一列中扫描条形码,然后基于该条形码的产品应显示在winforms的第一行,我们可以使用dgv.currentrow.cells []。value。我不知道wpf你可以帮我吗



我尝试过:



TextBox tbbarcode =发送者为TextBox;

DataTable dt = new DataTable();



dt = blOrderDetails.getProductsonBarcode(转换.ToString(tbbarcode.Text));



if(dt.Rows.Count> 0)

{

var item = dgvTextiles.SelectedItem as DataRowView;

if(item == null)return;



item.Row [ color] = dt.Rows [0] [color];

}

I had a wpf datagrid where I create a new row and I scan barcode in the firstcolumn then the products based on that barcode should be displayed on first row in winforms we can use dgv.currentrow.cells[].value . I donno about it in wpf can u help me

What I have tried:

TextBox tbbarcode = sender as TextBox;
DataTable dt = new DataTable();

dt = blOrderDetails.getProductsonBarcode(Convert.ToString(tbbarcode.Text));

if (dt.Rows.Count > 0)
{
var item = dgvTextiles.SelectedItem as DataRowView;
if (item == null) return;

item.Row["color"] = dt.Rows[0]["color"];
}

推荐答案

这是一个很好的做法基础数据源而不是直接修改数据网格。

您已经创建了数据表,为什么不将它用作数据源?



它应该是这样的

C#

It is a good practice to work on the underlying data source instead of modifying the data grid directly.
You have already created a data table so why not use it as the data source?

It should be something like this
C#
DataTable dtBarcodes = blOrderDetails.getProductsonBarcode(Convert.ToString(tbbarcode.Text));
dgvTextiles.DataContext = dtBarcodes.DefaultView;





XAML



XAML

<DataGrid Name="dgvTextiles" ItemsSource="{Binding}">


这篇关于当我扫描当前行本身的条形码时,如何为当前行指定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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