By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,011 Members | 2,967 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,011 IT Pros & Developers. It's quick & easy.

combox not changing when it's bind to a listbox with dataview sour

P: n/a
I have a window application. On one of the form, there is a listbox and a
few combox. The lstSchItem has a dataview as a datasource. The comboxes are
bind to its selected value but through the dataset table. Now when I change
the selection in the lstSchItem the comboxes are staying the same and not
reflecting the changes. I tried changing the binding to the dataview.table
but the comboxes are still not changing to reflect the different selection in
the lstSchItem. I appreciate some suggestions or help on how to correct this
problem.
Thank you, Alpha

cmbServiceItem.DataBindings.Add("SelectedValue",dv SchItems.Table,
"ExtServiceItemID");
cmbCycle1.DataBindings.Add("SelectedValue", dvSchItems.Table,
"ExtCycleID1");
cmbCycle2.DataBindings.Add("SelectedValue", dvSchItems.Table,
"ExtCycleID2");
cmbAndOr.DataBindings.Add("SelectedItem", dvSchItems.Table, "AndOr");


private void ScheduleItems_Load(object sender, System.EventArgs e)
{

try
{
cmbScheudle.DataSource = dsSchItems.Tables["Schedule"];
cmbScheudle.DisplayMember = "ScheduleName";
cmbScheudle.ValueMember = "SchID";
if(cmbScheudle.Items.Count>0)
cmbScheudle.SelectedIndex = 0;
else
btnAdd.Enabled = false;

tblSchItems = dsSchItems.Tables["ScheduleItems"];
dvSchItems.Table = tblSchItems;
if(cmbScheudle.Items.Count>0)
dvSchItems.RowFilter = FilterExp + cmbScheudle.SelectedValue.ToString();
dvSchItems.Sort = SortExp;

// lstSchItem.DataSource = dsSchItems.Tables["ScheduleItems"];
lstSchItem.DataSource = dvSchItems;
lstSchItem.DisplayMember = "SchItemCode";
lstSchItem.ValueMember = "SchItemID";

cmbServiceItem.DataSource = dsSchItems.Tables["ServiceItems"];
cmbServiceItem.DisplayMember = "ServiceName";
cmbServiceItem.ValueMember = "ServiceItemID";

cmbCycle1.DataSource = dsSchItems.Tables["ServiceCycle1"];
cmbCycle1.DisplayMember = "CLU";
cmbCycle1.ValueMember = "CycleID";

//Add a blank entry
DataRow BlankCyc2Item = dsSchItems.Tables["ServiceCycle2"].NewRow();
BlankCyc2Item["CycleID"] = -1;
BlankCyc2Item["CLU"] = "";
dsSchItems.Tables["ServiceCycle2"].Rows.Add(BlankCyc2Item);
dsSchItems.Tables["ServiceCycle2"].AcceptChanges();
cmbCycle2.DataSource = dsSchItems.Tables["ServiceCycle2"];
cmbCycle2.DisplayMember = "CLU";
cmbCycle2.ValueMember = "CycleID";

cmbAndOr.Items.Add("");
cmbAndOr.Items.Add("And");
cmbAndOr.Items.Add("Or");

// lstSchItem.DataBindings.Add("SelectedValue",
dsSchItems.Tables["Schedule"], "SchID");
cmbServiceItem.DataBindings.Add("SelectedValue",ds SchItems.Tables["ScheduleItems"], "ExtServiceItemID");
cmbCycle1.DataBindings.Add("SelectedValue",
dsSchItems.Tables["ScheduleItems"], "ExtCycleID1");
cmbCycle2.DataBindings.Add("SelectedValue",
dsSchItems.Tables["ScheduleItems"], "ExtCycleID2");
cmbAndOr.DataBindings.Add("SelectedItem",
dsSchItems.Tables["ScheduleItems"], "AndOr");
//if no schedule items to the selected scheudle then disable all the
related selection box

if (lstSchItem.Items.Count<=0)
{
// cmbServiceItem.SelectedValue = -1;
cmbServiceItem.Enabled = false;
// cmbCycle1.SelectedValue = -1;
cmbCycle1.Enabled = false;
// cmbCycle2.SelectedValue = -1;
cmbCycle2.Enabled = false;
// cmbAndOr.SelectedValue = -1;
cmbAndOr.Enabled = false;
}
else
{
// lstSchItem.SelectedIndex = 0;
ExtServiceItemID = Convert.ToInt32(cmbServiceItem.SelectedValue);
ExtCycleID1 = Convert.ToInt32(cmbCycle1.SelectedValue);
ExtCycleID2 = Convert.ToInt32(cmbCycle2.SelectedValue);
AndOr = cmbAndOr.SelectedItem.ToString();
}
First = false;
}
catch(Exception ex)
{
MessageBox.Show("Error binding the database to controls,please contact
your support person. : " + ex.ToString()
, "VMS - Control datasource error",
MessageBoxButtons.OK, MessageBoxIcon.Error);

}
}
Nov 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi,

"Alpha" <Al***@discussions.microsoft.com> wrote in message
news:18**********************************@microsof t.com...
I have a window application. On one of the form, there is a listbox and a
few combox. The lstSchItem has a dataview as a datasource. The comboxes
are
bind to its selected value but through the dataset table. Now when I
change
the selection in the lstSchItem the comboxes are staying the same and not
reflecting the changes. I tried changing the binding to the
dataview.table
but the comboxes are still not changing to reflect the different selection
in
the lstSchItem. I appreciate some suggestions or help on how to correct
this
problem.
If you bind lstSchItem to a DataView then you need to bind
SelectedValue/SelectedItem to the same DataView:

....
lstSchItem.DataSource = dvSchItems;
....
cmbServiceItem.DataBindings.Add("SelectedValue", dvSchItems,
"ExtServiceItemID");
....

HTH,
Greetings

Thank you, Alpha

cmbServiceItem.DataBindings.Add("SelectedValue",dv SchItems.Table,
"ExtServiceItemID");
cmbCycle1.DataBindings.Add("SelectedValue", dvSchItems.Table,
"ExtCycleID1");
cmbCycle2.DataBindings.Add("SelectedValue", dvSchItems.Table,
"ExtCycleID2");
cmbAndOr.DataBindings.Add("SelectedItem", dvSchItems.Table, "AndOr");


private void ScheduleItems_Load(object sender, System.EventArgs e)
{

try
{
cmbScheudle.DataSource = dsSchItems.Tables["Schedule"];
cmbScheudle.DisplayMember = "ScheduleName";
cmbScheudle.ValueMember = "SchID";
if(cmbScheudle.Items.Count>0)
cmbScheudle.SelectedIndex = 0;
else
btnAdd.Enabled = false;

tblSchItems = dsSchItems.Tables["ScheduleItems"];
dvSchItems.Table = tblSchItems;
if(cmbScheudle.Items.Count>0)
dvSchItems.RowFilter = FilterExp + cmbScheudle.SelectedValue.ToString();
dvSchItems.Sort = SortExp;

// lstSchItem.DataSource = dsSchItems.Tables["ScheduleItems"];
lstSchItem.DataSource = dvSchItems;
lstSchItem.DisplayMember = "SchItemCode";
lstSchItem.ValueMember = "SchItemID";

cmbServiceItem.DataSource = dsSchItems.Tables["ServiceItems"];
cmbServiceItem.DisplayMember = "ServiceName";
cmbServiceItem.ValueMember = "ServiceItemID";

cmbCycle1.DataSource = dsSchItems.Tables["ServiceCycle1"];
cmbCycle1.DisplayMember = "CLU";
cmbCycle1.ValueMember = "CycleID";

//Add a blank entry
DataRow BlankCyc2Item = dsSchItems.Tables["ServiceCycle2"].NewRow();
BlankCyc2Item["CycleID"] = -1;
BlankCyc2Item["CLU"] = "";
dsSchItems.Tables["ServiceCycle2"].Rows.Add(BlankCyc2Item);
dsSchItems.Tables["ServiceCycle2"].AcceptChanges();
cmbCycle2.DataSource = dsSchItems.Tables["ServiceCycle2"];
cmbCycle2.DisplayMember = "CLU";
cmbCycle2.ValueMember = "CycleID";

cmbAndOr.Items.Add("");
cmbAndOr.Items.Add("And");
cmbAndOr.Items.Add("Or");

// lstSchItem.DataBindings.Add("SelectedValue",
dsSchItems.Tables["Schedule"], "SchID");
cmbServiceItem.DataBindings.Add("SelectedValue",ds SchItems.Tables["ScheduleItems"],
"ExtServiceItemID");
cmbCycle1.DataBindings.Add("SelectedValue",
dsSchItems.Tables["ScheduleItems"], "ExtCycleID1");
cmbCycle2.DataBindings.Add("SelectedValue",
dsSchItems.Tables["ScheduleItems"], "ExtCycleID2");
cmbAndOr.DataBindings.Add("SelectedItem",
dsSchItems.Tables["ScheduleItems"], "AndOr");
//if no schedule items to the selected scheudle then disable all the
related selection box

if (lstSchItem.Items.Count<=0)
{
// cmbServiceItem.SelectedValue = -1;
cmbServiceItem.Enabled = false;
// cmbCycle1.SelectedValue = -1;
cmbCycle1.Enabled = false;
// cmbCycle2.SelectedValue = -1;
cmbCycle2.Enabled = false;
// cmbAndOr.SelectedValue = -1;
cmbAndOr.Enabled = false;
}
else
{
// lstSchItem.SelectedIndex = 0;
ExtServiceItemID = Convert.ToInt32(cmbServiceItem.SelectedValue);
ExtCycleID1 = Convert.ToInt32(cmbCycle1.SelectedValue);
ExtCycleID2 = Convert.ToInt32(cmbCycle2.SelectedValue);
AndOr = cmbAndOr.SelectedItem.ToString();
}
First = false;
}
catch(Exception ex)
{
MessageBox.Show("Error binding the database to controls,please contact
your support person. : " + ex.ToString()
, "VMS - Control datasource error",
MessageBoxButtons.OK, MessageBoxIcon.Error);

}
}

Nov 17 '05 #2

P: n/a
I binded them to the dvSchItems.Table. I removed the ".Table" and it works
now. Thank you very much.

Alpha

"Bart Mermuys" wrote:
Hi,

"Alpha" <Al***@discussions.microsoft.com> wrote in message
news:18**********************************@microsof t.com...
I have a window application. On one of the form, there is a listbox and a
few combox. The lstSchItem has a dataview as a datasource. The comboxes
are
bind to its selected value but through the dataset table. Now when I
change
the selection in the lstSchItem the comboxes are staying the same and not
reflecting the changes. I tried changing the binding to the
dataview.table
but the comboxes are still not changing to reflect the different selection
in
the lstSchItem. I appreciate some suggestions or help on how to correct
this
problem.


If you bind lstSchItem to a DataView then you need to bind
SelectedValue/SelectedItem to the same DataView:

....
lstSchItem.DataSource = dvSchItems;
....
cmbServiceItem.DataBindings.Add("SelectedValue", dvSchItems,
"ExtServiceItemID");
....

HTH,
Greetings

Thank you, Alpha

cmbServiceItem.DataBindings.Add("SelectedValue",dv SchItems.Table,
"ExtServiceItemID");
cmbCycle1.DataBindings.Add("SelectedValue", dvSchItems.Table,
"ExtCycleID1");
cmbCycle2.DataBindings.Add("SelectedValue", dvSchItems.Table,
"ExtCycleID2");
cmbAndOr.DataBindings.Add("SelectedItem", dvSchItems.Table, "AndOr");


private void ScheduleItems_Load(object sender, System.EventArgs e)
{

try
{
cmbScheudle.DataSource = dsSchItems.Tables["Schedule"];
cmbScheudle.DisplayMember = "ScheduleName";
cmbScheudle.ValueMember = "SchID";
if(cmbScheudle.Items.Count>0)
cmbScheudle.SelectedIndex = 0;
else
btnAdd.Enabled = false;

tblSchItems = dsSchItems.Tables["ScheduleItems"];
dvSchItems.Table = tblSchItems;
if(cmbScheudle.Items.Count>0)
dvSchItems.RowFilter = FilterExp + cmbScheudle.SelectedValue.ToString();
dvSchItems.Sort = SortExp;

// lstSchItem.DataSource = dsSchItems.Tables["ScheduleItems"];
lstSchItem.DataSource = dvSchItems;
lstSchItem.DisplayMember = "SchItemCode";
lstSchItem.ValueMember = "SchItemID";

cmbServiceItem.DataSource = dsSchItems.Tables["ServiceItems"];
cmbServiceItem.DisplayMember = "ServiceName";
cmbServiceItem.ValueMember = "ServiceItemID";

cmbCycle1.DataSource = dsSchItems.Tables["ServiceCycle1"];
cmbCycle1.DisplayMember = "CLU";
cmbCycle1.ValueMember = "CycleID";

//Add a blank entry
DataRow BlankCyc2Item = dsSchItems.Tables["ServiceCycle2"].NewRow();
BlankCyc2Item["CycleID"] = -1;
BlankCyc2Item["CLU"] = "";
dsSchItems.Tables["ServiceCycle2"].Rows.Add(BlankCyc2Item);
dsSchItems.Tables["ServiceCycle2"].AcceptChanges();
cmbCycle2.DataSource = dsSchItems.Tables["ServiceCycle2"];
cmbCycle2.DisplayMember = "CLU";
cmbCycle2.ValueMember = "CycleID";

cmbAndOr.Items.Add("");
cmbAndOr.Items.Add("And");
cmbAndOr.Items.Add("Or");

// lstSchItem.DataBindings.Add("SelectedValue",
dsSchItems.Tables["Schedule"], "SchID");
cmbServiceItem.DataBindings.Add("SelectedValue",ds SchItems.Tables["ScheduleItems"],
"ExtServiceItemID");
cmbCycle1.DataBindings.Add("SelectedValue",
dsSchItems.Tables["ScheduleItems"], "ExtCycleID1");
cmbCycle2.DataBindings.Add("SelectedValue",
dsSchItems.Tables["ScheduleItems"], "ExtCycleID2");
cmbAndOr.DataBindings.Add("SelectedItem",
dsSchItems.Tables["ScheduleItems"], "AndOr");
//if no schedule items to the selected scheudle then disable all the
related selection box

if (lstSchItem.Items.Count<=0)
{
// cmbServiceItem.SelectedValue = -1;
cmbServiceItem.Enabled = false;
// cmbCycle1.SelectedValue = -1;
cmbCycle1.Enabled = false;
// cmbCycle2.SelectedValue = -1;
cmbCycle2.Enabled = false;
// cmbAndOr.SelectedValue = -1;
cmbAndOr.Enabled = false;
}
else
{
// lstSchItem.SelectedIndex = 0;
ExtServiceItemID = Convert.ToInt32(cmbServiceItem.SelectedValue);
ExtCycleID1 = Convert.ToInt32(cmbCycle1.SelectedValue);
ExtCycleID2 = Convert.ToInt32(cmbCycle2.SelectedValue);
AndOr = cmbAndOr.SelectedItem.ToString();
}
First = false;
}
catch(Exception ex)
{
MessageBox.Show("Error binding the database to controls,please contact
your support person. : " + ex.ToString()
, "VMS - Control datasource error",
MessageBoxButtons.OK, MessageBoxIcon.Error);

}
}


Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.