none
Getting value of ComboBox in Datagridview Control

    Question

  • I have a databound combobox column in a datagridview control.

    The combobox contains a list of possible name prefixes "Mr, Mrs, Dr." etc.  

    As the contents of the datagrid may result in multiple records for the same person being shown I want to ensure that if I reset the Prefix for a person on one of those records it will reset all the others in the grid.

    I have some code that will go through the dataset used to populate the grid and reset the values for that person but I cant seem to get the value of the combobox cell to pass to this function.

    I'm currently using the cell validating event to highlight any duplicate records in a different color and want to reset the values to that matching the currently changed item.

    Any ideasd of how I can get the value of the currently edited combobox in the grid ?

    Monday, October 10, 2005 6:59 PM

All replies

  • try me.datagridview.currentcell.value.tostring
    ddd
    Wednesday, May 04, 2011 2:56 PM
  • If you want to get the value on validating time (so you can decide to accept or decline) you have to use CellValidating event, othewise you can use CellEndEdit event; this event is called, when validation gas gone through.

     

        public Form1()
        {
          InitializeComponent();
          dataGridView1.CellValidating += new DataGridViewCellValidatingEventHandler(dataGridView1_CellValidating);
          dataGridView1.CellEndEdit += new DataGridViewCellEventHandler(dataGridView1_CellEndEdit);
        }
    
        //1. case
        private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
        {
          string value = e.FormattedValue.ToString();
        }
    
        //2. case
        private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
          string value = dataGridView1.CurrentCell.ToString();
        }
    


    Mitja
    Wednesday, May 04, 2011 4:02 PM