473,372 Members | 854 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,372 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 1413
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Floela | last post by:
I want to set a the MappingName of a DataGridTableStyle to "ArrayList" in an ASP.NET page, but the class is stored in the System.Windows.Forms namespace. It won't let me import the namespace at...
3
by: Rxd | last post by:
I have a Datagrid that should have a couple of hidden columns. I used a DataGridTableStyle to hide the columns and it was working fine except I needed to prevent the DataGrid from allowing new rows...
2
by: Carlos | last post by:
Does DataGridTableStyle work in ASP.net ? any time I'm tring to define a varibale lke DataGridTableStyle MyStyle = new DataGridTableStyle(); it give me "The Type or name sapce...
2
by: Scott | last post by:
Hi all. A few days ago i ask this question and got a good quick response. I tried out what they said and it worked. However I have now come to try the same thing in another program and it...
2
by: Carlos | last post by:
Does DataGridTableStyle work in ASP.net ? any time I'm tring to define a varibale lke DataGridTableStyle MyStyle = new DataGridTableStyle(); it give me "The Type or name sapce...
2
by: kerpal | last post by:
Hi all, 1. Could anyone pls clarify the difference between setting the AlternatingBackColor property in DataGridTableStyle and in DataGrid?? 2. How come BackColor and AlternatingBackColor are...
4
by: Brett Romero | last post by:
I have the following DataGridTableStyle: DataGridTableStyle gridTableStyle = new DataGridTableStyle(); gridTableStyle.MappingName = "myStyle"; DataGridTextBoxColumn dgsc = new...
3
by: nita | last post by:
I'm just starting out, and it's incredibly frustrating when I see sample code and then try to implement it. Case in point. I'm populating a collection then binding it to a datagrid. That works...
7
by: Mitchell S. Honnert | last post by:
Is there an equivalent of the DataGrid's DataGridTableStyle for the DataGridView? If not, is there an easy way to duplicate the DataGridTableStyle's functionality for the DataGridView? Here's...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.