DataGrid Binding to subset of Dataset?

  • Thread starter Thread starter J
  • Start date Start date
J

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.TableStyles.Clear();
DataGridTableStyle ts1 = new DataGridTableStyle();
ts1.MappingName = "page";

DataGridColumnStyle TextCol = new DataGridTextBoxColumn();
TextCol.MappingName = "id";
TextCol.HeaderText = "id";
TextCol.Width = 30;
TextCol.ReadOnly = true;
ts1.GridColumnStyles.Add(TextCol);

TextCol = new DataGridTextBoxColumn();
TextCol.MappingName = "DOCID";
TextCol.HeaderText = "DOCID";
TextCol.Width = 50;
TextCol.ReadOnly = false;
ts1.GridColumnStyles.Add(TextCol);

dataGrid3.SetDataBinding(pDS, "page");
dataGrid3.TableStyles.Add (ts1);

CurrencyManager cm = (CurrencyManager)BindingContext
[dataGrid1.DataSource, "page"];
DataView dv = (DataView)cm.List;
dv.AllowNew = false;
-------------------------------------
 
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.TableStyles.Clear();
DataGridTableStyle ts1 = new DataGridTableStyle();
ts1.MappingName = "page";

DataGridColumnStyle TextCol = new DataGridTextBoxColumn();
TextCol.MappingName = "id";
TextCol.HeaderText = "id";
TextCol.Width = 30;
TextCol.ReadOnly = true;
ts1.GridColumnStyles.Add(TextCol);

TextCol = new DataGridTextBoxColumn();
TextCol.MappingName = "DOCID";
TextCol.HeaderText = "DOCID";
TextCol.Width = 50;
TextCol.ReadOnly = false;
ts1.GridColumnStyles.Add(TextCol);

dataGrid3.SetDataBinding(pDS, "page");
dataGrid3.TableStyles.Add (ts1);

CurrencyManager cm = (CurrencyManager)BindingContext
[dataGrid1.DataSource, "page"];
DataView dv = (DataView)cm.List;
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.TableStyles.Clear();
DataGridTableStyle ts1 = new DataGridTableStyle();

ts1.MappingName = "page";

ts1.AlternatingBackColor = Color.MediumOrchid;

DataGridColumnStyle TextCol = new DataGridTextBoxColumn();
TextCol.MappingName = "id"; //from dataset table
TextCol.HeaderText = "id";
TextCol.Width = 30;
TextCol.ReadOnly = true;
ts1.GridColumnStyles.Add(TextCol);

TextCol = new DataGridTextBoxColumn();
TextCol.MappingName = "DOCID"; //from dataset table
TextCol.HeaderText = "DOCID";
TextCol.Width = 50;
TextCol.ReadOnly = false;
ts1.GridColumnStyles.Add(TextCol);

dataGrid3.SetDataBinding(pDS, "page");
dataGrid3.TableStyles.Add (ts1);
dataGrid3.DataMember = "page";

CurrencyManager cm =
(CurrencyManager)BindingContext[dataGrid1.DataSource, "page"];
DataView dv = (DataView)cm.List;
//---------------------------------
//This will 'Filter' the dataset
string txtFilter;
txtFilter = "DOCID=" + g_Cur_D;
dv.RowFilter = txtFilter;
//---------------------------------
dv.AllowNew = false;
 
Back
Top