473,395 Members | 1,978 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,395 software developers and data experts.

auto default GridColumnStyles

Whats wrong with this code?
DataSet ds = new DataSet();

DataTable tbl = new DataTable("Tbl");
tbl.Columns.Add("field1", typeof(string));
tbl.Columns.Add("field2", typeof(string));
tbl.Columns.Add("field3", typeof(int));
ds.Tables.Add(tbl);

DataTable tbl2 = new DataTable("Tbl2");
tbl2.Columns.Add("field1", typeof(string));
tbl2.Columns.Add("field2", typeof(string));
tbl2.Columns.Add("field3", typeof(int));
ds.Tables.Add(tbl2);

dataGrid1.DataSource = ds;
dataGrid1.DataMember = tbl.TableName;

DataGridTableStyle ts = new DataGridTableStyle();
ts.MappingName = tbl.TableName;
dataGrid1.TableStyles.Add(ts);
dataGrid1.TableStyles[tbl.TableName].GridColumnStyles["field3"].Width=0;

ts = new DataGridTableStyle();
ts.MappingName = tbl2.TableName;
dataGrid1.TableStyles.Add(ts);
dataGrid1.TableStyles[tbl2.TableName].GridColumnStyles["field2"].Width=0;

This last line causes an "Object reference not set to an instance of an
object" error.
If I change the DataMember to tbl2 before adding the last TableStyle, no
error.
Apparently just adding a TableStyle to the TableStyles collection doesn't
automatically generate a complete set of default ColumnStyles as the
documentation states. What exactly is the rule here?
Feb 28 '06 #1
1 1437
Russ,
Apparently just adding a TableStyle to the TableStyles collection doesn't
automatically generate a complete set of default ColumnStyles as the
documentation states. What exactly is the rule here?


In my experience, the documentation does oversimplify quite a bit on
this point. I ran into similar problems with a grid that wasn't sited
(i.e. BindingContext was nothing). It took quite a while to trace down
the real source of the problem because there is no diagnostic
information (no error message) when the TableStyle is not automatically
populated.

Unfortunately, other than commiseration, I don't have anything concrete
to offer. In my case, I was using a utility subroutine for configuring
my data grids, so I added code to throw an error if the number of
columns in the TableStyle was different than the number in the
DataTable. At least that way I can start out a couple of steps closer
to the root cause when I do have a problem.

-JLS

Mar 21 '06 #2

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

Similar topics

20
by: Vijay Kumar R. Zanvar | last post by:
Hello, Unlike register, auto keyword can not be used to declare formal parameter(s). Is there any specific reason for this? Kind regards, Vijay Kumar R. Zanvar
2
by: Jim Dougherty | last post by:
I am using c#.net 2003 and have an an application with a datagrid. The binding is with an array of structs. Everything works ok except the header text is the struct element names and they override...
1
by: Darryn Ross | last post by:
Hi, I am adding records into my datagrid and everytime i add a new record the default values are all (null). How do i get away from this and set some defaults of my own. I have a custom table...
5
by: Lars Netzel | last post by:
Is it possible to asign a default value to a cell in a DataGrid column when using TableStyle as well? I have an ID column with a width= 0 that has to have a default ID value when the user adds...
2
by: boclair | last post by:
I have just been reading the thread "reason behind containing block rule" It reminded me of a question I have had unresolved for some time What are the rules on the default width of an element...
9
by: Beowulf | last post by:
I was having this problem: http://groups.google.com/group/microsoft.public.sqlserver.server/msg/e36e423972323378?dmode=source with it taking an inordinate amount of time to enumerate the...
4
by: =?Utf-8?B?TWFyaw==?= | last post by:
Hi... Following the samples online, we implemented a windows service in .Net. Like most services, there's a worker thread actually doing stuff in the background. The problem we've run into is...
2
by: GTalbot | last post by:
www.authoring.html] Hello fellow HTML and markup coder colleagues, Please visit this url: http://www.gtalbot.org/BrowserBugsSection/DefaultTopBottomMarginsForPargDisappear.html I would...
3
by: TS | last post by:
I am using IE 7. I have a website running on my local machine (localhost) and auto complete doesnt work for any of the textboxes, but going to web sites on the internet does support this so i know...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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,...
0
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...
0
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...
0
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...
0
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,...

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.