473,396 Members | 2,036 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,396 software developers and data experts.

dataGrid confusion

I am having trouble wrapping my head around a datagrid and datasource.
I have it working, sort-of, but I'm having trouble refreshing my views.
Here's what I have:

A dataAdapter and dataSet generated by the wizards.

I click my Orders button, grid displays as expected.

I click my drop down box to filter out some specific records, every
thing works as expected.

When I click my Orders button again, it simply shows whatever the last
filter displayed. I've tried every little hack I can think of. Clearly,
I don;t have a good understanging of the C# datagrid yet. Any help is
GREATLY appriciated. Below is my code. Thanks in Advance!!!
private void btnOrders_Click(object sender, System.EventArgs e)
{
lblHeading.Text = "ORDERS: Supplier Num Part Num Quantity";

if (conn.State != ConnectionState.Open)
conn.Open();

// Set the datasource to the dataset
dataGrid.DataSource = dataSetSP.SP;
dataAdapterSP.Fill(dataSetSP);

// Populate the ComboBox
dataAdapterS.Fill(dataSetS);
}

private void cmbSupplier_SelectedIndexChanged(object sender,
System.EventArgs e)
{
if (conn.State != ConnectionState.Open)
conn.Open();

DataView dv = dataSetSP.Tables["SP"].DefaultView;
string filter = "`S#` = '" + cmbSupplier.SelectedValue + "'";
dv.RowFilter = filter;
dataGrid.DataSource = dv;

}

Nov 17 '05 #1
1 1374
Hi,
[Inline]

"Guy Noir" <ah******@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
I am having trouble wrapping my head around a datagrid and datasource.
I have it working, sort-of, but I'm having trouble refreshing my views.
Here's what I have:

A dataAdapter and dataSet generated by the wizards.

I click my Orders button, grid displays as expected.

I click my drop down box to filter out some specific records, every
thing works as expected.

When I click my Orders button again, it simply shows whatever the last
filter displayed. I've tried every little hack I can think of. Clearly,
I don;t have a good understanging of the C# datagrid yet. Any help is
GREATLY appriciated. Below is my code. Thanks in Advance!!!


There are some variations to solve this, here's one:

Even if you bind to a DataSet/DataTable the grid is always bound to a
DataView, it isn't DefaultView, but you can get the right DataView using the
CurrencyManager for the table :

/*
Make sure you bound the datagrid in the designer (or from code: eg.onload):
DataSource = dataSetSP;
DataMember = "SP";
*/

private void btnOrders_Click(object sender, System.EventArgs e)
{
lblHeading.Text = "ORDERS: Supplier Num Part Num Quantity";

if (conn.State != ConnectionState.Open)
conn.Open();

// refresh/ populate grid
dataSetSP.Clear();
dataAdapterSP.Fill(dataSetSP);

// refresh/ populate ComboBox
dataSetS.Clear();
dataAdapterS.Fill(dataSetS);

// instead of re-setting the datasource here, clear the rowfilter
DataView dv = (DataView)((CurrencyManager)BindingContext[dataSetSP,
"SP"]).List;
dv.RowFilter = "";

con.Close();
}

private void cmbSupplier_SelectedIndexChanged(object sender,
System.EventArgs e)
{
DataView dv = (DataView)((CurrencyManager)BindingContext[dataSetSP,
"SP"]).List;
string filter = "`S#` = '" + cmbSupplier.SelectedValue + "'";
dv.RowFilter = filter;
}

--- Another way though similar, is to bind the grid to the table's
DefaultView from the beginning (onload) and never change the binding, but
only change/clear its RowFilter.
HTH,
Greetings
Nov 17 '05 #2

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

Similar topics

2
by: Bill C. | last post by:
Hi, I'm trying to implement a ComboBox drop-down column for a DataGrid. When a cell is selected in the ComboBox column I overlay a ComboBox over the cell and call: this.comboBox.Show();...
1
by: Joe Bloggs | last post by:
I am trying display the contents of a table in a web page, select certain rows from that table and then display the fields that I have selected (now table columns) as text in a Label object....
3
by: Brett Hargreaves | last post by:
Hi, I'm having trouble with the datagrid update command. I have a datagrid called grid that poulates itself with data in the page load event. When I click the edit button it takes me into...
7
by: Pete Davis | last post by:
A different question this time. I have a DataGrid bound to a collection. Is there any way for me to allow sorting? The DataGrid.AllowSorting=true doesn't work, but that's probably because it can't...
3
by: Christopher Jedlicka | last post by:
Hi, I am trying to use a datagrid control to display hierarchical data in a flat format essentially in a master-detail relationship. i.e. <Data> <Customer CustomerName="Customer1"> <Order...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
8
by: Sue | last post by:
I have a datagrid populated with 6 visible read-only labels and several hidden fields. Below the datagrid, I have a table with various textboxes, dropdowns, etc. I've managed to decypher the...
1
by: David Tilman | last post by:
I have an ASP .NET web application that changes datagrid cells in the ItemDataBound event, like changing the Columnspan of a cell to 2 and deleting the adjacent cell, so that I have two cells...
14
by: Brett Sinclair | last post by:
Hello everybody I'm still on the learning curve here...and from what I read, I created inherited datagrid class so I could have icons, combobox...etc in the columns of my datagrid. The grid...
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.