1

i have a datagridview bould on a list from Mongodb. however i cannot edit the grid. I dunno why its like that?

var connstr = "Server=localhost:27017";
mongo = new Mongo(connstr);
mongo.Connect();

IMongoDatabase TorontoTrader = mongo["TorontoTrader"];
IMongoCollection TradingStrategyCollection = TorontoTrader["TradingStrategyRefresher"];
IEnumerable<Document> docs =
   from doc in TradingStrategyCollection.Linq()
   where (int)doc["TriggerBarId"] == 102
   select doc;

dataGridView1.ReadOnly = false;
dataGridView1.DataSource = docs.First().ToList();
i3arnon
  • 113,022
  • 33
  • 324
  • 344
junkone
  • 1,427
  • 1
  • 20
  • 45
  • 1
    First guess would be that ToList is not returning a collection that has an IEditable interface which is required for gridview editing – Roadie57 Oct 13 '10 at 15:42
  • I am not sure becuase under the debugger, the readonly attribute is set to false. http://screencast.com/t/dC63vfoT4 – junkone Oct 13 '10 at 16:02
  • My understanding is that your collection must support the IEditable interface for a datagrid to support built in in row editing. – Roadie57 Oct 13 '10 at 16:41
  • is there any example that you can point to. I am not sure what is the next step i should take. Becoz, the docs.First().ToList() is a MongoDB C# driver implementation that i have no control on immediately. In the interim, how can i make it work. – junkone Oct 13 '10 at 17:09
  • From what I have seen about MongoDB it does not return a Datatable or DataReader or any of the mainstream data objects. It looks like you would have to add your own controls and catch change events to do in row editing. – Roadie57 Oct 13 '10 at 18:01
  • Ouch that doesn't sounds like fun! – Paul C Aug 04 '11 at 13:31

1 Answers1

0

I guess you must set the ItemsSource of your datagridview to an observableCollection instance.

dataGridView1.DataSource = new ObservableCollection<Document>(docs.First());

This probably will make the grid editable, but it will not save back the edits to the database.

Jone Polvora
  • 2,184
  • 1
  • 22
  • 33