Note that there are some explanatory texts on larger screens.

plurals
  1. PODatagridview bound to object - Making the new rows appear blank
    primarykey
    data
    text
    <p>I have a Datagridview that changes its content according to a selection the user makes in a listBox. The DGV consits of 2 comboboxes (Country, Product) and 1 textbox (Quantity).</p> <p>I've created a class combined of 3 integers. This class is used as a type of list, which is the datasource for the DGV. There is also another list containing the prior list, so I have a list of datasources.</p> <p>The DGV's datasource is a BindingSource that changes whenever the SelectedIndex of the listBox is fired.</p> <p>My problem occurs whenever a new row is added to the DGV: I use the BindingSource.AddNew which calls the constructor of the class, but <strong>it must assign values to each item in the class</strong>. That way, whenever I click any cell in the DGV I don't get a blank row. Moreover, when the BS changes and then returned, another row is added.</p> <p>What I want to get is a blank row - empty comboboxes and textbox.</p> <p>Thanks for your help!</p> <p>The class:</p> <pre><code> Public Class PoList Private _CountryID As Integer Private _ProductID As Integer Private _Quantity As Integer Public Sub New(ByVal CountryID As Integer, ByVal ProductID As Integer, ByVal Quantity As Integer) _CountryID = CountryID _ProductID = ProductID _Quantity = Quantity End Sub Private Sub New() _CountryID = 1 _ProductID = 2 _Quantity = Nothing End Sub Public Property CountryID() As Integer Get Return _CountryID End Get Set(ByVal value As Integer) _CountryID = value End Set End Property Public Property ProductID() As Integer Get Return _ProductID End Get Set(ByVal value As Integer) _ProductID = value End Set End Property Public Property Quantity() As Integer Get Return _Quantity End Get Set(ByVal value As Integer) _Quantity = value End Set End Property Public Shared Function CreateNewPoList() As PoList Return New PoList End Function End Class Private Sub List_AddRow(ByVal sender As Object, ByVal e As AddingNewEventArgs) Handles AllListBindingSource.AddingNew e.NewObject = PoList.CreateNewPoList End Sub </code></pre> <p>Creating a new inner list:</p> <pre><code>AllList.Add(New List(Of PoList)) AllListBindingSource.AddNew() AllListBindingSource.DataSource = AllList(TableCounter) AddPoDetails.DataSource = AllListBindingSource </code></pre> <p>SelectedIndexChanged event:</p> <pre><code>AllListBindingSource.DataSource = AllList(AddPoList.SelectedIndex) AddPoDetails.DataSource = Nothing AddPoDetails.DataSource = AllListBindingSource </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload