471,317 Members | 1,459 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,317 software developers and data experts.

How to debug DataGridTableStyle?

When I create this table and add it to my DataGrid (framework v1.1),
the TableStyle works fine:

DataTable dt = new DataTable();
DataColumn dc = new DataColumn("AreaCode");
DataColumn dctwo = new DataColumn("Test");
dt.Columns.Add(dc);
dt.Columns.Add(dctwo);

I have the style set to only show AreaCode. However, when I use a
table from the database, every column displays. AreaCode is a column
in this table, which means I should only see AreaCode in the grid.

I've looked at the grid properties in the debugger and see the
tablestyle AreaCode column is there. I also see in the DataTable a
column named AreaCode. What else do I need to look for to figure it
out?

Thanks,
Brett

Jan 24 '06 #1
9 1328
Brett,

The problem here isn't the grid and how it is set up, but rather, the
table itself. You say when you get a database from the table, this happens.
Well, are you selecting all of the fields, or some of them? If it is all of
them, then that's what you are going to see in the grid.

You need to cut down your selection so that you only select the fields
that you want.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Brett Romero" <ac*****@cygen.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
When I create this table and add it to my DataGrid (framework v1.1),
the TableStyle works fine:

DataTable dt = new DataTable();
DataColumn dc = new DataColumn("AreaCode");
DataColumn dctwo = new DataColumn("Test");
dt.Columns.Add(dc);
dt.Columns.Add(dctwo);

I have the style set to only show AreaCode. However, when I use a
table from the database, every column displays. AreaCode is a column
in this table, which means I should only see AreaCode in the grid.

I've looked at the grid properties in the debugger and see the
tablestyle AreaCode column is there. I also see in the DataTable a
column named AreaCode. What else do I need to look for to figure it
out?

Thanks,
Brett

Jan 24 '06 #2
That's not completely correct Nick. I'm doing this with a custom
datagrid. On the regular winform datagrid, I use a tablestyle to
dispay 8 of 10 fields returned in the set from a database.

This has to be something specific to my custom grid. It's puzzling
though b/c the little two column table I created works with the custom
grid. I can display 1 of 2 columns. How is that any different than
what comes from the database and is put into a dataset, which I then
reference?

It has more column than I want displayed. However, the tablestyle
takes care of that. Just not yet because I'm missing something in my
custom grid's logic, which I'm trying to pin point.

Thanks,
Brett

Jan 24 '06 #3
Brett,
Try using MappingType.Hidden to suppress display of columns you don't want
displayed, e.g.:
ds.Tables[2].Columns["DeviceTypeModelID"].ColumnMapping = MappingType.Hidden;

Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Brett Romero" wrote:
When I create this table and add it to my DataGrid (framework v1.1),
the TableStyle works fine:

DataTable dt = new DataTable();
DataColumn dc = new DataColumn("AreaCode");
DataColumn dctwo = new DataColumn("Test");
dt.Columns.Add(dc);
dt.Columns.Add(dctwo);

I have the style set to only show AreaCode. However, when I use a
table from the database, every column displays. AreaCode is a column
in this table, which means I should only see AreaCode in the grid.

I've looked at the grid properties in the debugger and see the
tablestyle AreaCode column is there. I also see in the DataTable a
column named AreaCode. What else do I need to look for to figure it
out?

Thanks,
Brett

Jan 24 '06 #4
Brett,

Well, post a code sample and let's see for ourselves.

DataSets that are populated from a DataAdapter tend to be no different
than anything populated by hand. However, that doesn't mean that when you
populate something by hand, you might miss what a DataAdapter might normally
set.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Brett Romero" <ac*****@cygen.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
That's not completely correct Nick. I'm doing this with a custom
datagrid. On the regular winform datagrid, I use a tablestyle to
dispay 8 of 10 fields returned in the set from a database.

This has to be something specific to my custom grid. It's puzzling
though b/c the little two column table I created works with the custom
grid. I can display 1 of 2 columns. How is that any different than
what comes from the database and is put into a dataset, which I then
reference?

It has more column than I want displayed. However, the tablestyle
takes care of that. Just not yet because I'm missing something in my
custom grid's logic, which I'm trying to pin point.

Thanks,
Brett

Jan 24 '06 #5
I use the MS DataAccess block, which uses an sqlhelper. It returns a
data reader, which I loop through to create a dataset. So there isn't
a data adapter involved in the code. What else can I post?

Thanks,
Brett

Jan 24 '06 #6
Hi,

"Brett Romero" <ac*****@cygen.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
When I create this table and add it to my DataGrid (framework v1.1),
the TableStyle works fine:

DataTable dt = new DataTable();
DataColumn dc = new DataColumn("AreaCode");
DataColumn dctwo = new DataColumn("Test");
dt.Columns.Add(dc);
dt.Columns.Add(dctwo);

I have the style set to only show AreaCode. However, when I use a
table from the database, every column displays. AreaCode is a column
in this table, which means I should only see AreaCode in the grid.

I've looked at the grid properties in the debugger and see the
tablestyle AreaCode column is there. I also see in the DataTable a
column named AreaCode. What else do I need to look for to figure it
out?
The first thing to check when DGColumnStyle's don't seem to work is whether
you have set the correct MappingName for the DGTableStyle,
DGTableStyle.MappingName must be the same as the bound DataTable.TableName.

DataGridTableStyle dgts = new DataGridTableStyle();
dgts.MappingName = someDataTable.TableName; // !!

.... add DataGridColumnStyles ...

someDataGrid.TableStyles.Add( dgts );
someDataGrid.DataSource = someDataTable;
HTH,
Greetings

Thanks,
Brett

Jan 24 '06 #7
Well, SOME code would have been helpful, but I digress.

Why are you populating the data set yourself? You should be able to
tell the data access block to populate the data set for you, using a data
adapter.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Brett Romero" <ac*****@cygen.com> wrote in message
news:11*********************@g44g2000cwa.googlegro ups.com...
I use the MS DataAccess block, which uses an sqlhelper. It returns a
data reader, which I loop through to create a dataset. So there isn't
a data adapter involved in the code. What else can I post?

Thanks,
Brett

Jan 24 '06 #8
Bart, you absolutely got it! That was the disconnect. The table name
and tablestyle mappingname were different.

I'd like to override DataSource() in my custom grid so I can look for
the table name. This way I can be sure the mapping and table names are
always the same. However, the datasource may take a dataset, datatable
or dataview. I'd need to know how to get at the table to retreive the
table name. Do I need to setup switch statements in the DataSource()
method, look for each type and extract the table name?

Thanks,
Brett

Jan 24 '06 #9
Hi,

"Brett Romero" <ac*****@cygen.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
Bart, you absolutely got it! That was the disconnect. The table name
and tablestyle mappingname were different.

I'd like to override DataSource() in my custom grid so I can look for
the table name. This way I can be sure the mapping and table names are
always the same. However, the datasource may take a dataset, datatable
or dataview. I'd need to know how to get at the table to retreive the
table name. Do I need to setup switch statements in the DataSource()
method, look for each type and extract the table name?
A little advanced, but you could use a CurrencyManager for this.
CurrencyManager.List points to the list that is actually bound, that list
will implement ITypedList if it has a name otherwise the type-name must be
used, example:

// DataMember can be an empty string (eg. when bound to DataTable)
CurrencyManager cm = (CurrencyManager)
BindingContext[DataSource, DataMember];

ITypedList typedList = cm.List as ITypedList;
string listName = "";
if ( typedList!=null )
listName = typedList.GetListName(null);
else
listName = cm.List.GetType().Name;

That should work for almost anything (DataSet, DataTable, DataView, custom
lists, arrays ).

Offcourse you could also use a switch but then it's less generic.

HTH,
Greetings

Thanks,
Brett

Jan 24 '06 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Floela | last post: by
2 posts views Thread by Carlos | last post: by
2 posts views Thread by Scott | last post: by
2 posts views Thread by Carlos | last post: by
4 posts views Thread by Brett Romero | last post: by
3 posts views Thread by nita | last post: by
7 posts views Thread by Mitchell S. Honnert | last post: by
reply views Thread by rosydwin | last post: by

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.