I'm not sure if this is the right place to post this, but as there is no .NET forum (only a VB.NET and ASP.NET forums) and I'm using C#, so here I go. :)

I have a datagridview with a single combobox per row. I want to populate that combobox based on another value in the same row. I've tried looking for an appropriate event to populate it, but am not sure which event to use. I've tried using the CellFormatting event, but that doesn't appear to be very efficient.

Any suggestions on the best way to accomplish this?

Thanks in advance.

Ed.

This is the right place. It could be called C#.NET but then again there are other C# compilers out there.
A DataGridView1 has a Rows collection, you can set values in it with an indexer(this is a TextBox example)
MydataGridView[1, 2].Value = "new value";
Set the value of the second cell of the third row. Hope it helps.

OK, maybe I wasn't clear. :) I know how to access a cell in a datagridview. What I'm trying to figure out is how to populate a combobox inside a datagridviewcell. The grid in question is databound, and as the combobox is dependent on a value in the same row, I need to populate the box after the row is populated. So, I need some suggestions on what event to use. I know I can use the DataBound event in ASP.NET, but I can't seem to find a corresponding event for WinForms. Any clues appreciated.

Ed.

OK, I guess I found my answer: The RowsAdded event.

Now I have a new question: the combobox being populated is being populated from a web service. I go through all the proper steps and everything appears to be executing correctly -- the webservice code is used elsewhere and works -- but the combo box is being displayed empty; it doesn't appear to be populated. I'm sure I'm missing something here, any clues appreciated:

private void dgvTitles_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e) {
      DataGridViewComboBoxColumn combo = (DataGridViewComboBoxColumn)dgvTitles.Rows[e.RowIndex].Cells["cmbCopyID"].OwningColumn;
      int title = int.Parse(dgvTitles.Rows[e.RowIndex].Cells[2].Value.ToString());
      EDanaIILibraryWebService.LibraryDataSet.AvailableCopiesDataTable data
      = service.FindAvailableCopies(title);
      combo.DataSource = data;
      combo.ValueMember = "ISBNCopy";
      combo.DisplayMember = "ISBNCopy";
    }

Ed.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.