I hope someone can help me on this. I have two controls on a form.
the first is a comboBox the second is a datagrid. Both controls are bound
to tables in
a common dataset. What I am trying to get to happen is to have the value
from the combobox control what populates the datagrid.
I have two data adapters, the second of which uses a parameterized query to
populate its referenced table in the dataset. I have two issues. first how
to fill the second control when form is first shown and second how to
refresh the second control.
this.cmbPeriod.DataSource = this.dtPeriod;// this is the table object
this.cmbPeriod.DisplayMember = "period_name"; // this is the column from the
period table that displays
this.cmbPeriod.Name = "cmbPeriod";
// this is the column from the period table that I want to be returned as
the selectedIndex
// the period_id is what I want to pass as the parameter value to fill the
other control
this.cmbPeriod.ValueMember = "period_id";
this.cmbPeriod.SelectedValueChanged += new
System.EventHandler(this.cmbPeriod_SelectedValueCh anged);
//
// daOrg This is the second data adapter association with table
named organization
//
this.daOrg.SelectCommand = this.cmdSelectOrg;
//
// cmdSelectOrg This is the select command associated with data
adapter daOrg
//
this.cmdSelectOrg.CommandText = "SELECT id AS org_id, hier_path AS
org_hier_path, name AS org_name, order_index AS" +
" org_index, period_id, original_id AS org_original_id FROM
dbo.organization WHER" +
"E (period_id = @period_id) ORDER BY hier_path";
this.cmdSelectOrg.Connection = this.cnSoComply;
this.cmdSelectOrg.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@period_id", System.Data.SqlDbType.Int,
4, "period_id"));
//
// dgOrg this is the data grid I am trying to fill
//
this.dgOrg.DataMember = "";
this.dgOrg.DataSource = this.dtOrganization;
// This is the Selected Value changed event handler for the
comboBox cmbPeriod
private void cmbPeriod_SelectedValueChanged(object sender,
System.EventArgs e)
{
//I need to pass the value of the the select period row period_id field
here
// I thought by assigned the ValueMember to period_id that selectedIndex
would return
// that number but that is not the case.
daOrg.SelectCommand.Parameters["@period_id"].Value =
cmbPeriod.SelectedIndex;
daOrg.Fill(dsSoComply,"Organization");
}
I am still confused as to how to populate the grid the first time it is
shown because I don't think the SelectedValueChanged event fires at that
point.