DataGrid: How to insert a row when bound to an ArrayList?

  • Thread starter Steven Van Dyke
  • Start date
S

Steven Van Dyke

This should be simple, but I cannot figure it out. Given a datagrid, bound
to an arraylist, how should I go about inserting a new row above a selected
row?

Thanks,

Steve
 
S

serge gubenko

Hi,

IMO, since ArrayList isn't implementing IBindingList interface there is a
problem with adding and removing its items in DataGrid. You could create
your own list and implement IBindingList there in order to solve this
problem. Another quick workaround is to "rebind" arraylist each time you
adding a new row. Here's an example:

_____________________________
ArrayList mList = new ArrayList();

{...}

mList.Add(new MyItem(...));
dataGrid1.DataSource = null;
dataGrid1.DataSource = mList;
dataGrid1.Select(mList.Count-1);

where dataGrid1 is
System.Windows.Forms.DataGrid
_____________________________
hope this helps

Best regards, Serge Gubenko
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top