title: How to programmatically select value in ASPxComboBox in ASpxGridView
body: <p>I am required to use the DevExpress ASPxGridView. I have a datasource Object which returns two columns of importance, ObjectType and ObjectID. ObjectType can be Patient or or Physician. ObjectID is a int value giving the ID of the Patient  or Physician. Hopefully this makes sense. The ObjectID is selected by either the Patient table or the Physician table, they are indendent tables so I can't join them in any way.</p>
  
  <p>The table structure looks like this:</p>
  
  <p>Object table: ObjectType varchar ("Physician" or "Patient"), ObjectID int</p>
  
  <p>Dogs Table ID int, Name varchar</p>
  
  <p>Cats table ID int, Name varchar</p>
  
  <p>I have been able to write the appropriate objectType by a combobox, and the ObjectID by using two controls, cbPatient and cbPhysician, which are populated by datasources.</p>
  
  <p>What I can't figure out is when I edit the ASPxGridView, how can I show in cbPatient or cbPhysician the object value. For example if ObjectType is Cats and ObjectID is 1 then I want to show in cbCats the name that corresponds with ID of 1. </p>
  
  <p>This is how the code looks.  Right now, for whatever reason the selected value goes blank at some point, in some event.  I'm not sure what event to run this code in.  </p>
  
  <pre><code>protected void grid_HtmlRowCreated(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewTableRowEventArgs e)
  {
      if (e.RowType != DevExpress.Web.ASPxGridView.GridViewRowType.EditForm) return;
      if (grid.IsNewRowEditing || grid.IsEditing)
      {
          int val = (int)grid.GetRowValues(grid.EditingRowVisibleIndex, "ObjectID" );
  
          ASPxComboBox cbPatient = ((ASPxComboBox)grid.FindEditRowCellTemplateControl(grid.Columns["PatientID"] as GridViewDataComboBoxColumn, "cbPatient"));
          if (val != 0)
          {
              string objectID = grid.GetRowValues(grid.EditingRowVisibleIndex, "ObjectID").ToString();
  
              if (cbPatient.Items.Count &gt; 0)
              {
                  cbPatient.Items[1].Selected = true;
              }
              else
              {
                  cbPatient.DataSource = dsPatName;
                  cbPatient.DataBindItems();
                  if (cbPatient.Items.Count &gt; 0)
                      cbPatient.Items[1].Selected = true;
              }
  
          }
      }
  
  }
  </code></pre>
  
  <p>This is the ASPX code.</p>
  
  <pre><code>&lt;/dx:GridViewDataComboBoxColumn&gt;
  &lt;dx:GridViewDataComboBoxColumn Caption="Patient Name" FieldName="PatientID"  Name="PatName"  Visible="false"&gt;
      &lt;PropertiesComboBox TextField="Name" ValueField="ID" ValueType="System.Int32"&gt;&lt;/PropertiesComboBox&gt;
      &lt;EditItemTemplate&gt;
          &lt;dx:ASPxComboBox ID="cbPatient" runat="server"  TextField="Name" ValueField="ID"
          Value='&lt;%# Bind("PatientID") %&gt;' AutoPostBack="false" ValueType="System.Int32" &gt; &lt;/dx:ASPxComboBox&gt;
      &lt;/EditItemTemplate&gt;
  &lt;/dx:GridViewDataComboBoxColumn&gt;
  </code></pre>