Click here to Skip to main content
15,888,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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"];
}
Posted
Updated 29-May-16 19:07pm

1 solution

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#
C#
DataTable dtBarcodes = blOrderDetails.getProductsonBarcode(Convert.ToString(tbbarcode.Text));
dgvTextiles.DataContext = dtBarcodes.DefaultView;


XAML
XML
<DataGrid Name="dgvTextiles" ItemsSource="{Binding}">
 
Share this answer
 
Comments
girishmdr 30-May-16 1:12am    
here dtbarcodes will give the values based on a particular barcode so dtbarcodes eventually changes according to corresponding barcode.
George Jonsson 30-May-16 1:16am    
You don't specify the structure of the data table returned by getProductsonBarcode() and you don't specify what structure you want to present in the grid view, so it is not easy to give more specific advice.

Create a new data table then, with a static structure that can be shown in the grid and use that as a data source.

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