473,653 Members | 3,000 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.EventArg s e)
{
lblHeading.Text = "ORDERS: Supplier Num Part Num Quantity";

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

// Set the datasource to the dataset
dataGrid.DataSo urce = dataSetSP.SP;
dataAdapterSP.F ill(dataSetSP);

// Populate the ComboBox
dataAdapterS.Fi ll(dataSetS);
}

private void cmbSupplier_Sel ectedIndexChang ed(object sender,
System.EventArg s e)
{
if (conn.State != ConnectionState .Open)
conn.Open();

DataView dv = dataSetSP.Table s["SP"].DefaultView;
string filter = "`S#` = '" + cmbSupplier.Sel ectedValue + "'";
dv.RowFilter = filter;
dataGrid.DataSo urce = dv;

}

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

"Guy Noir" <ah******@gmail .com> wrote in message
news:11******** **************@ g47g2000cwa.goo glegroups.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.EventArg s e)
{
lblHeading.Text = "ORDERS: Supplier Num Part Num Quantity";

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

// refresh/ populate grid
dataSetSP.Clear ();
dataAdapterSP.F ill(dataSetSP);

// refresh/ populate ComboBox
dataSetS.Clear( );
dataAdapterS.Fi ll(dataSetS);

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

con.Close();
}

private void cmbSupplier_Sel ectedIndexChang ed(object sender,
System.EventArg s e)
{
DataView dv = (DataView)((Cur rencyManager)Bi ndingContext[dataSetSP,
"SP"]).List;
string filter = "`S#` = '" + cmbSupplier.Sel ectedValue + "'";
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
2486
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(); this.comboBox.BringToFront(); this.comboBox.Focus();
1
2518
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. Amazingly I have managed to display the table - no problem, I can select rows - no problem, BUT I can't work out how to display more than one of the fields (now columns in the table in the web page). I can display one field OK, but not more than one...
3
2207
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 edit mode no pronlem, however when I change the data in the edit cell it is not picking up the newly typed value, it passes back the original value. eg, the orgincal value is
7
4222
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 assume the data types and thus can't sort them. I thought about implementing IComparable, but I don't see how that would work since it doesn't apply generically to all the fields/properties of the class. Thanks.
3
1314
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 OrderNumber="1"> <Item ItemName="Item1"></Item> <Item ItemName="Item2"></Item>
3
4871
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 the best method? Do you have a sample of how to do this?
8
3046
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 client-side coding needed for the user to click a "select" button (HTMLButton) in column 0 of the datagrid and have the table objects auto-fill with corresponding values from the dataset row in the datagrid without making a roundtrip to the server. ...
1
1316
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 merged into one. I was wanting to do something similar in another part of the program (right after the DataBind() for the datagrid). Where I could select a particular cell index and row index and merge two cells of the datagrid. What is the best...
14
1830
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 will be used to populate information coming from a Webservice. (No datasets - No datareaders). So, I do not know see how to use the "datasource".
0
8370
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8283
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8811
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8470
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7302
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4147
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4291
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2707
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1591
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.