I am developing a win form application
and i am stuck in a situation with data grid view
.
what i exactly want to do is, if i enter some bar code then according to the bar-code
i want to get data and fill them in the the combo box
of brand name and Item name and mrp and all.
Which event should i work on and how can i get data and fill in this data grid-view
row.

- 13,072
- 12
- 67
- 75

- 1,145
- 6
- 25
- 50
-
I hope my time will be useful result to have new ideas and solutions – daniele3004 Nov 08 '14 at 08:17
-
Need more clarification? – daniele3004 Nov 08 '14 at 11:14
2 Answers
You can do this in many ways, my experience with DataGridView I do as follows. Suppose you have a model class for your dataGridView
public class MyBarcodeRow
{
private String barcode = String.Empty;
public String Barcode
{
get { return barcode; }
set {
barcode = value;
////TODO OPERATION ON OTHER FIELD
//FOR EXAMPLE GET DATA OF QUANTITY FROM DATABASE
this.Quantity = new Random().Next(Int32.MaxValue);
}
}
private int quantity = 0;
public int Quantity
{
get { return quantity; }
set { quantity = value; }
}
//AND OTHER FIELD
}
In your form drag a BindingSource and associated it
BindingSource.DataSource = MyBarcodeRow
Now when you insert the barcode and leave cells you can load other data values.
From experience I suggest you focus on the events of the BindingSource and the Get / Set methods of the class of model that uses the VIEW.
Then there are also many interesting events in the grid, however, these structures work best when used from this point of view

- 13,072
- 12
- 67
- 75
Use DataGridViewComboBoxColumn.DataSource
.
For example you have a class of Brand
public class Brand
{
public int32 ID {get; set;}
public string Name {get; set;}
}
In the form
create a list of Brands and fill it with data(from database I assume)
List<Brand> _brands;
this.dgvBrandNamesColumn.DataSource = _brands;
this.dgvBrandNamesColumn.DisplayMemeber = "Name";
this.dgvBrandNamesColumn.ValueMemeber = "Name";
After adding data to DataGridView
DataGridViewComboBoxColumn
will select matched brand name from DataSource(_brands
)
For more specific help, show code how fill datagridview with data and how/from where you get all brands names

- 31,528
- 4
- 33
- 72