473,395 Members | 1,978 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,395 software developers and data experts.

How to refesh a listbox bind to a dataview?

I have a listbox with datasource from a dataview. When a user selects a
different item in a combobox then I need to refresh the listbox to the
appropriate listing based on that combobox's selected value which is included
in the listbox's filtering statement.

Is the only way to do this is to dispose the dataview and then create a new
one and then bind it to the listbox? Is there a better way than this?

Thanks, Alpha
Nov 17 '05 #1
6 12878
Alpha,

Is the datasource of your listbox a "new DataView" or is it the DefaultView
of a table.

If I understand you right is it the first, therefore try to use that
DefaultView.

I hope this helps,

Cor

"Alpha" <Al***@discussions.microsoft.com> schreef in bericht
news:6E**********************************@microsof t.com...
I have a listbox with datasource from a dataview. When a user selects a
different item in a combobox then I need to refresh the listbox to the
appropriate listing based on that combobox's selected value which is
included
in the listbox's filtering statement.

Is the only way to do this is to dispose the dataview and then create a
new
one and then bind it to the listbox? Is there a better way than this?

Thanks, Alpha

Nov 17 '05 #2
It's not a defaultview. The dataview is created at the loading of the form.
It has a filter value that is determined by the user's selection of the
comboBox above it. I need to refresh the listbox to reflect the proper
listing according to what is selected in the comboBox.

Both comboBox and the listbox dataview are getting their data from the same
dataset but different table. The dataview is used to filter the table
information to the corrsponding selection in comboBox.

Is there a way to do this with dataview? I guess I could always use the the
dataset.table as the datasource for the listbox and then clear and fill each
time the new selection is made with the comboBox. I just thought that's not
very efficient way to do it and would like to see if I can do this with
dataview.

Thanks, Alpha

"Cor Ligthert [MVP]" wrote:
Alpha,

Is the datasource of your listbox a "new DataView" or is it the DefaultView
of a table.

If I understand you right is it the first, therefore try to use that
DefaultView.

I hope this helps,

Cor

"Alpha" <Al***@discussions.microsoft.com> schreef in bericht
news:6E**********************************@microsof t.com...
I have a listbox with datasource from a dataview. When a user selects a
different item in a combobox then I need to refresh the listbox to the
appropriate listing based on that combobox's selected value which is
included
in the listbox's filtering statement.

Is the only way to do this is to dispose the dataview and then create a
new
one and then bind it to the listbox? Is there a better way than this?

Thanks, Alpha


Nov 17 '05 #3
Alpha,

Normally you can do that using the indexchange event of the first control to
set the dataview.rowfilter of the second one with the text or the
selectedvalue.

While you can as well use the currencymanager change event for that.

For a combobox or listbox I normally use the first. Be aware that you set
the indexchange handler after that you have set the datasource, the
displaymember and eventualy the valuemember of the combobox.

I hope this helps,

Cor
Nov 17 '05 #4
Hi Cor,

I already coded before the following in the cmbScheudle_SelectedIndexChanged
event but the listbox still doesn't reflect the new listing according to the
new id selected in the comboBox. Can you tell what I'm doing wrong?

int SelSch = Convert.ToInt32(cmbScheudle.SelectedValue.ToString ());
strScheudleID =
dsSchItems.Tables["Schedule"].Rows[SelSch]["SchID"].ToString();

dvSchItems.Dispose();
DataView dvNewSchItems = new DataView();
int SelSch = Convert.ToInt32(cmbScheudle.SelectedValue.ToString ());
strScheudleID =
dsSchItems.Tables["Schedule"].Rows[SelSch]["SchID"].ToString();
dvNewSchItems.Table = tblSchItems;
dvNewSchItems.RowFilter = FilterExp + strScheudleID;
dvNewSchItems.Sort = SortExp;

lstSchItem.DataSource = dvNewSchItems;
lstSchItem.DisplayMember = "SchItemCode";
lstSchItem.ValueMember = "SchItemID";

lstSchItem.Refresh();

"Cor Ligthert [MVP]" wrote:
Alpha,

Normally you can do that using the indexchange event of the first control to
set the dataview.rowfilter of the second one with the text or the
selectedvalue.

While you can as well use the currencymanager change event for that.

For a combobox or listbox I normally use the first. Be aware that you set
the indexchange handler after that you have set the datasource, the
displaymember and eventualy the valuemember of the combobox.

I hope this helps,

Cor

Nov 17 '05 #5
Alpha,

If you use a new project, drag on that a combobox and a listbox and than
past in this code, than you will see how it goes (you have to make the load
event as well)

\\\
private void Form1_Load(object sender, EventArgs e)
{
//building of sample tables
DataTable dt1 = new DataTable();
DataTable dt2 = new DataTable();
dt1.Columns.Add("Id",Type.GetType("System.String") );
dt1.Columns.Add("ListID", Type.GetType("System.String"));
dt1.LoadDataRow(new Object[] { 1,"Field1" }, true);
dt1.LoadDataRow(new Object[] { 2, "" }, true);
dt1.LoadDataRow(new Object[] { 3, "Field3" }, true);
dt2.Columns.Add("ListId", Type.GetType("System.String"));
dt2.Columns.Add("Show", Type.GetType("System.String"));
dt2.LoadDataRow(new Object[] { "Field1", "The Fields one" }, true);
dt2.LoadDataRow(new Object[] { "Field3", "Another Field" }, true);
dt2.LoadDataRow(new Object[] { "Field3", "Again Antoher Field" },
true);
//end building tables

//start sample
comboBox1.DataSource = dt1;
comboBox1.DisplayMember = "Id";
comboBox1.ValueMember = "ListId";
dt2.DefaultView.RowFilter = "ListId = '" + dt1.Rows[0][1] + "'";
listBox1.DataSource = dt2.DefaultView;
listBox1.DisplayMember = "Show";
listBox1.ValueMember = "ListId";
comboBox1.SelectedIndexChanged +=
new System.EventHandler(this.Combobox1_SelectedIndexCh anged);
}
private void Combobox1_SelectedIndexChanged(object sender, EventArgs e)
{
((DataView)listBox1.DataSource).RowFilter =
"ListId = '" + comboBox1.SelectedValue +"'";
}
///

I hope this helps,

Cor
Nov 17 '05 #6
Sorry it took me so long to respond. I was pull away to take care of
something else. My earlier error was trying to just setting the rowfilter of
the dataview and that didn't work. I used the code you have at the end which
tied in the control and dataview and it worked. Thank you very much!

"Cor Ligthert [MVP]" wrote:
Alpha,

If you use a new project, drag on that a combobox and a listbox and than
past in this code, than you will see how it goes (you have to make the load
event as well)

\\\
private void Form1_Load(object sender, EventArgs e)
{
//building of sample tables
DataTable dt1 = new DataTable();
DataTable dt2 = new DataTable();
dt1.Columns.Add("Id",Type.GetType("System.String") );
dt1.Columns.Add("ListID", Type.GetType("System.String"));
dt1.LoadDataRow(new Object[] { 1,"Field1" }, true);
dt1.LoadDataRow(new Object[] { 2, "" }, true);
dt1.LoadDataRow(new Object[] { 3, "Field3" }, true);
dt2.Columns.Add("ListId", Type.GetType("System.String"));
dt2.Columns.Add("Show", Type.GetType("System.String"));
dt2.LoadDataRow(new Object[] { "Field1", "The Fields one" }, true);
dt2.LoadDataRow(new Object[] { "Field3", "Another Field" }, true);
dt2.LoadDataRow(new Object[] { "Field3", "Again Antoher Field" },
true);
//end building tables

//start sample
comboBox1.DataSource = dt1;
comboBox1.DisplayMember = "Id";
comboBox1.ValueMember = "ListId";
dt2.DefaultView.RowFilter = "ListId = '" + dt1.Rows[0][1] + "'";
listBox1.DataSource = dt2.DefaultView;
listBox1.DisplayMember = "Show";
listBox1.ValueMember = "ListId";
comboBox1.SelectedIndexChanged +=
new System.EventHandler(this.Combobox1_SelectedIndexCh anged);
}
private void Combobox1_SelectedIndexChanged(object sender, EventArgs e)
{
((DataView)listBox1.DataSource).RowFilter =
"ListId = '" + comboBox1.SelectedValue +"'";
}
///

I hope this helps,

Cor

Nov 17 '05 #7

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

Similar topics

1
by: Harlin Seritt | last post by:
I am trying to poll selections from a listbox but can't seem to get it to work correctly. class pollstuff: def __init__(self, master): self.listbox = Listbox(master) self.listbox.pack() ...
1
by: Arthur Dzhelali | last post by:
I according to MSDN dataview and dataset are thread safe for read operations, but we run into this scenario. I just would like to see some comments on it. Aplication written in VB.NET it is an...
1
by: GeraldBauer | last post by:
I am experiencing some weird behaviors with the listbox and dataview. Here is a boiled down code snippet of what I am trying to do. <snippet> string MENUID = "MenuId" , ITEM = "Item" ,...
4
by: Jazper Manto | last post by:
hi i bounded the same dataview to 2 different comboboxes. now, when i change the selectedIndex of combobox1, it automatically changes the selectedIndex of combobox2. does this mean, that the...
2
by: Alpha | last post by:
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...
1
by: kroyce | last post by:
Is there a way to bind an arraylist to a dataview?
0
by: =?Utf-8?B?cm9kY2hhcg==?= | last post by:
hey all, i have 2 columns (first and last name) in my dataview. how do i bind that to my dropdownlist? i'd like to get just the first name in the box. thanks, rodchar
0
by: crespo | last post by:
hi,everyone. I have a question about using listbox in a customized user control.I use a listbox directly in a asp.net page and it works very well,but when I use the same code in a user...
1
by: MariaKhan | last post by:
?? bind DataSet with listbox ??? ?? bind DataSet with listbox ??? ?? bind DataSet with listbox ??? ?? bind DataSet with listbox ??? ?? bind DataSet with listbox ???
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.