473,614 Members | 2,377 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataGrid Binding to subset of Dataset?

J
This works well for binding a Dataset (created from an XML file) to a
DataGrid for the entire 'page' table. However I would like to only
grab a few rows from the 'page' table (like: select id, description
from page where docid = 1).

Any help would be greatly appreciated... because this datagrid thing
is kicking my ass.

Thank you,

J
-------------------------------------
dataGrid3.Table Styles.Clear();
DataGridTableSt yle ts1 = new DataGridTableSt yle();
ts1.MappingName = "page";

DataGridColumnS tyle TextCol = new DataGridTextBox Column();
TextCol.Mapping Name = "id";
TextCol.HeaderT ext = "id";
TextCol.Width = 30;
TextCol.ReadOnl y = true;
ts1.GridColumnS tyles.Add(TextC ol);

TextCol = new DataGridTextBox Column();
TextCol.Mapping Name = "DOCID";
TextCol.HeaderT ext = "DOCID";
TextCol.Width = 50;
TextCol.ReadOnl y = false;
ts1.GridColumnS tyles.Add(TextC ol);

dataGrid3.SetDa taBinding(pDS, "page");
dataGrid3.Table Styles.Add (ts1);

CurrencyManager cm = (CurrencyManage r)BindingContex t
[dataGrid1.DataS ource, "page"];
DataView dv = (DataView)cm.Li st;
dv.AllowNew = false;
-------------------------------------
Nov 16 '05 #1
1 2250
J
jt*****@eudoram ail.com (J) wrote in message news:<e2******* *************** ****@posting.go ogle.com>...
This works well for binding a Dataset (created from an XML file) to a
DataGrid for the entire 'page' table. However I would like to only
grab a few rows from the 'page' table (like: select id, description
from page where docid = 1).

Any help would be greatly appreciated... because this datagrid thing
is kicking my ass.

Thank you,

J
-------------------------------------
dataGrid3.Table Styles.Clear();
DataGridTableSt yle ts1 = new DataGridTableSt yle();
ts1.MappingName = "page";

DataGridColumnS tyle TextCol = new DataGridTextBox Column();
TextCol.Mapping Name = "id";
TextCol.HeaderT ext = "id";
TextCol.Width = 30;
TextCol.ReadOnl y = true;
ts1.GridColumnS tyles.Add(TextC ol);

TextCol = new DataGridTextBox Column();
TextCol.Mapping Name = "DOCID";
TextCol.HeaderT ext = "DOCID";
TextCol.Width = 50;
TextCol.ReadOnl y = false;
ts1.GridColumnS tyles.Add(TextC ol);

dataGrid3.SetDa taBinding(pDS, "page");
dataGrid3.Table Styles.Add (ts1);

CurrencyManager cm = (CurrencyManage r)BindingContex t
[dataGrid1.DataS ource, "page"];
DataView dv = (DataView)cm.Li st;
dv.AllowNew = false;
-------------------------------------


It's amazing what time will do... I've figured this out now. I
believe this is the way you would want to do this (while this dataGrid
this still sucks):

I've modified the above code to show the change:

dataGrid3.Table Styles.Clear();
DataGridTableSt yle ts1 = new DataGridTableSt yle();

ts1.MappingName = "page";

ts1.Alternating BackColor = Color.MediumOrc hid;

DataGridColumnS tyle TextCol = new DataGridTextBox Column();
TextCol.Mapping Name = "id"; //from dataset table
TextCol.HeaderT ext = "id";
TextCol.Width = 30;
TextCol.ReadOnl y = true;
ts1.GridColumnS tyles.Add(TextC ol);

TextCol = new DataGridTextBox Column();
TextCol.Mapping Name = "DOCID"; //from dataset table
TextCol.HeaderT ext = "DOCID";
TextCol.Width = 50;
TextCol.ReadOnl y = false;
ts1.GridColumnS tyles.Add(TextC ol);

dataGrid3.SetDa taBinding(pDS, "page");
dataGrid3.Table Styles.Add (ts1);
dataGrid3.DataM ember = "page";

CurrencyManager cm =
(CurrencyManage r)BindingContex t[dataGrid1.DataS ource, "page"];
DataView dv = (DataView)cm.Li st;
//---------------------------------
//This will 'Filter' the dataset
string txtFilter;
txtFilter = "DOCID=" + g_Cur_D;
dv.RowFilter = txtFilter;
//---------------------------------
dv.AllowNew = false;
Nov 16 '05 #2

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

Similar topics

10
3086
by: ShadowsOfTheBeast | last post by:
hi all i am trying to bind data to my datagrid from a listbox which i think it should work but an error is coming up saying i have to bind to a datasource that implements the Inumerable or icollection...but i thought list boxes did implement one of the above as they do have their items collection property, can anyone help?
5
2581
by: Jeff | last post by:
IDE: VS 2003 :NET OS: XP Pro My app have a form with a tab-control on it. The tab-control have 2 tabpages. One of the tabpages displays a datagrid, and the other tabpage displays details (order date, name, address etc) about the selected row in the datagrid... My problem is when I enter a new record in the details tabpage (saves data to database), and go back to the datagrid. Only the data from the PM-table
4
2829
by: Steve B. | last post by:
I have a DataGrid on the left and TextBoxes (TB) on the right. The TB's reflect the contents of the grid cells. Sorting of columns (both thru VS and programmatically) work fine except, when the form/grid first opens up and the grid is immediately sorted the TB don't reflect the sorted data of the First row of the grid. Note: Initially the black grid indicator arrow points to the first row. If the user choses another row and then sorts...
0
3490
by: Dave | last post by:
Tried posting in the Winform Forum without much luck, so posting here... After inserting a new data row to a DataTable that is bound to a datagrid, I am unable to change data in a row that is after the newly added row without getting bizarre results. I have added the full code for the test below. Create a project drop in the code and run. There is nothing crazy about the code. I used the designer to add the dataset and to do the...
6
3317
by: Alpha | last post by:
I have several textboxes that I need to chang the text when the selection row is changed in a datagrid. I have the following code. This textbox displayes the initial selection but when I click on different rows in the datagrid, the textbox content doesn't change to reflect the change. How can I address this? Also, If the user change the text in the textbox then how do I refesh the display in the datagrid to reflect the changes? ...
3
4868
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?
2
1642
by: Dave | last post by:
Hi, When binding a dataset to a DataGrid and paging 10 records at a time, is the entire dataset still encoded and sent to viewstate as well OR just the current page and what's visible to the user stored in the viewstate on the browser? I've added some excerpts from some articles so I'm not sure. Any other MS links verifying this would be great.
1
1380
by: Geraldine Hobley | last post by:
Hello, I have a problem whereby I have a datagrid and and extra field all bound to the same dataset. I can easily edit rows in the dataset by changing the bindingposition in the MyGrid_currentcellchanged event of Mygrid, using the following function Private Function GetBindingPosition(ByVal IntMatchValue As Integer, ByVal MyMatchField As String, ByVal MyDataTable As DataTable) As Integer Dim i As Integer = 0 Dim blnValueFnd As Boolean ...
17
2747
by: A_PK | last post by:
I have problem databinding the DataGrid with DataView/DataSet after the filter... I create the following proceudre in order for user to filter as many as they want, but the following code is only allow user to filter the first time, when they tried the second time, the speficied cast error message will prompt one.... I create a mydataset1 first, and the mydataset1 data source was getting from DataGrid.DataSource.
0
8176
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
8571
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8265
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
8423
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7047
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
4048
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
4115
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1705
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1420
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.