473,320 Members | 2,000 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Trying to figure out how to link two controls

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.
Nov 17 '05 #1
1 1510
if the datagrid doesn't populate off the form loading, then can't you run it
manually in your form constructor?
After you set your combo box datasource, you should check if their are rows,
set it to a default position (ie: 0), and call your event handler manually
if it isn't firing. Your hanlder won't fire since you haven't defined your
event handler before you assigned your datasource... and imo this is good,
because it's easier to control what happens by calling config stuff manually
at the time you set your datasource.

As for getting your value from the combo box, SelectedIndex is the index of
the row in it's collection (the combolist). You are looking for
SelectedValue. You will have to cast the return to the correct type. As an
alternative you can also get it by retrieving the entire data row (as a data
row view object).

DataRowView r = cmbPeriod.Items[cmbPeriod.SelectedIndex] as DataRowView;

"Henry" <hs****@onproject.com> wrote in message
news:O$*************@TK2MSFTNGP14.phx.gbl...
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.

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Gopal Krish | last post by:
I'm have coded a simple menu (using link buttons as menu items) in a user control to be reused across many ASPX pages. In the page_load method I dynamically create the link buttons as follows ...
9
by: Boris Yeltsin | last post by:
I use Master Pages, so I make use of URL rebasing through the ~ operator, like this in the <head>: <link runat="server" href="~/Root.master.css" media="screen" rel="stylesheet" type="text/css" />...
2
by: rodchar | last post by:
hey all, i was just wondering when does the DataList_SelectedIndexChanged ever occur. I've only used it as a container for other controls such as a link button. thanks, rodchar
3
by: RallyDSM | last post by:
Pre STory - I've had a lot of problems with this program, and I just added the last part of it (the add item code) and now an older part of the program crashes. Public Structure Stocks Public...
3
by: Mark | last post by:
Assume you want to dynamically add one to many link button controls to a web page dynamically at run time. Each link button needs to post back and execute code. As the link buttons are created at...
10
richardhodge
by: richardhodge | last post by:
I am a VB6 database programmer and have run into a small problem. The company I work for primarily uses Microsoft Access 2000 for the database that is the back end for our software. Well the...
3
by: John Kotuby | last post by:
Hi all... I am trying to do a simple thing and maybe am missing something elementary. I have created a Javascript function at the top of a page which is meant to enable editing of an HTML input...
1
by: rsteph | last post by:
I've got some product information pages, with images and text, all setup within a table. I'm trying to add a small image in the upper right hand corner of the content div (where all the important...
0
by: grasshopper2 | last post by:
I am trying to update a table on a sql 2000 or 2005 box ( am not sure what version its running how do I check?) I am so green I feel like kermit the frog! computer is running windows 2000,...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.