Tech Off Thread

5 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

DataGridView, ComboBox and Generics.ArrayList(Of MyObject1)

Back to Forum: Tech Off
  • User profile image
    Klaus Enevoldsen

    I have a DataGridView that data binds to an ArrayList (Generics of MyClass1). I have added colums and the objects that already are in the ArrayList are shown just fine.

    Problem 1) I cannot seem to add new rows to the grid. There is proberbly som event I have to respond to or something...

    I also want a ComboBox to show the same data as the DataGridView (to select a default object from the list of objects).

    Problem 2) But when the selected item of the Grid is changed it also changes the selected item in the ComboBox...

    Thanks in advance...

  • User profile image
    jcfiala

    Klaus Enevoldsen wrote:
    I have a DataGridView that data binds to an ArrayList (Generics of MyClass1). I have added colums and the objects that already are in the ArrayList are shown just fine.

    Problem 1) I cannot seem to add new rows to the grid. There is proberbly som event I have to respond to or something...


    I've just started playing around with the DataGridView control myself.  How are you trying to add new rows to the grid?  Programatically?  Or by clicking on the empty row of the grid and typing?

    If the latter, you need to look at the settings for what keystrokes begins a row add.  I fiddled with that (code not in front of me) and it started working.  Also note that the 'AddRows' event fires as soon as you start adding a new row- not when you finish.

    John

  • User profile image
    Klaus Enevoldsen

    Hi,

    I'm pressing arrow down when on the last line of the grid, but nothing happens. I wonder if there is an interface or something that I have to implement.

    I'll try to fiddle with the different settings and see what happens.

    Thanks for your reply...

    Klaus

  • User profile image
    Klaus Enevoldsen

    After hours of studying the problem, I found the solution. Apparently for databinding to be able to add new rows to the data grid view, the data source has to implement the interface IBindableList. List(Of T) does not implement IBindableList. But I found the class System.ComponentModel.BindingList(Of T) and it just works... Great!

    I still haven't found a solution for problem 2)...

  • User profile image
    nkotb

    Hi,

    can i know how to go about to insert a new row in between rows in the DataGridView in VB.NET???

    Regards,

    nkotb

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.