Now then,

It's not often I start a thread but I'm struggling to find the answer after a lot of tries on Google.

The issue is that I have a "Profession" comboBoxCell as well as a "Discipline" comboBoxCell which is populated/ repopulated with a short list of disciplines dependent on the value selected in the "Profession comboBoxCell.

This would mean I'd need a selectedValue Changed action event at cell (just the "Profession" comboBoxCell) level rather than the entire DGV or that counts for all cells like below:

dataGridView1_CellValueChanged()

If anyone could suggest anything other than point me in the right direction I would really appreciate it.

So you could raise the CellContentClick event on the DGV..

private void dataGridViewMain_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if(e.ColumnIndex == 2)//2 is whichever column your combobox is
            {
                //do something with value
            }

        }

Is that what you mean or did you want to get the value of the ComboBox??

Yes I need to get the value of the ComboBox cell when the event occurs so it can be passed to a stored proc (all that is working);

Does the CellContentClicked event only fire if the content is click (i know it sound obvious) or when content is selected (when content or display value is changed as a result of an auto populate method)?

The main problem I'm having with cell level events is if there is 8 columns and 8 rows, which means the event will fire for every cell (64 times) even if isnt in column specified in the if statement (column 2 in the above example) which is the problem.

Does the ColumnDisplayIndexChanged() meth fire if display index of ComoBoxCell under the specified column is changed ?
If it does it could be the better option becauce it means it would only fire once if per click wouldn't it.

Thanks for the reply too...

Hi, from what I can gather, you want to spcify exactly which cell is being changed and then send your value off to wherever from that?

You would be better off using the CurrentDirtyStateChanged event of your DGV.

 private void dataGridView1_CurrentCellDirtyStateChanged(object sender, EventArgs e)
 {
  DataGridViewRow dgrv = dgv.CurrentRow; //get the row clicked
  int row = dgvr.Index;

  int colIndex = dgv.CurrentCell.ColumnIndex;//with row and colIndex, 
  //work out exactly which cell has been clicked.

  //if for instance you want to specify exactly where your comboBox is..
  if(row == 1 && colIndex == 3)
  {
  dgv.CommitEdit(DataGridDataErrorContexts.Commit);//you must commit first

  DataGridViewComboBoxCell cb = (DataGridViewComboBoxCell) dgv.rows[row].Cells[colIndex];

  string value = cb.Value.ToString();//this is your value, do whatever you want with it...
  }
  }

Hope that helps I think that is what you are trying to do? Sorry it is a bit messy.

Yeah I want an event to fire if a cell, within a particular column, or any given row is clicked.

I havent run the code above yet but I assume it runs if any cell on the DGV is clicked by isolating the row and column clicked. It will work and be less labour intensive as the other options I've tried so far, but i think it will still be too much.

Having looked at your suggestion though it has given me an idea. Like your checking for a dirty cell and isolating of the row first. i was going to ask if using the ColumnDisplayIndexChanged and then getting the row would be any quicker but it doesnt seem as though any of them will.

All the event methods are too generic for what i'm looking for so I'm just going to create a form which pops up when the user wants to add new records and refresh the DGV on the first form when the user clicks add. I know it will be more work but it will make it more usable and intuitive for the users.

I'll no doubt use your solutions in the future or if the users decide they dont like the idea of the pop-up form.

Thanks again for your time James.

Ok, at least it has given you something to start with..good luck.

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.