473,466 Members | 1,406 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

custom datagrid

Hi!

I have extended the default windows.forms datagrid... I added a few options
if the data is bound programmaticly... The main part of the function (the
for loop) loops through all the columns and creates a DataGridTextBoxColumn
or DataGridBoolColumn for each of them...
The problem is, that the DataGrid always displays just one of the columns!
I have tried binding the DataTable after adding the TableStyle but that
didn't work... I have also tried
using the AddRange method and adding all of the columns at once but that
doesn't work either...
I really don't know what I'm doing wrong...

Any help?
Saso

Here is the code:

public void InitDataGrid(DataTable table)

{

this.DataBindings.Clear();

this.TableStyles.Clear();
this.SetDataBinding(table,"");
DataGridTableStyle ts1 = new DataGridTableStyle();

ts1.MappingName = "mainTable";

// Set other properties.

ts1.AlternatingBackColor = Color.AliceBlue;

DataGridColumnStyle[] textCol = new
DataGridColumnStyle[this.GridColumns.Length];

/* Add a GridColumnStyle and set its MappingName

to the name of a DataColumn in the DataTable.

Set the HeaderText and Width properties. */

for ( int i = 0;i < this.GridColumns.Length;i++ )

{

if ( ( this.ColumnTypes == null ) || (this.ColumnTypes.Length !=
this.GridColumns.Length) )

{

textCol[i] = new DataGridTextBoxColumn();

}

else

{

if ( this.ColumnTypes[i] == ColumnType.TextBox )

{

textCol[i] = new DataGridTextBoxColumn();

}

else

{

textCol[i] = new DataGridBoolColumn();

}

}
textCol[i].MappingName = this.GridColumns[i];
if ( (this.HeaderText == null ) || (this.HeaderText.Length !=
this.GridColumns.Length) )

{

textCol[i].HeaderText = this.GridColumns[i];

}

else

{

textCol[i].HeaderText = this.HeaderText[i];

}

if ( ( this.ColumnSizes == null ) || (this.ColumnSizes.Length !=
this.GridColumns.Length) )

{

textCol[i].Width = DEFAULT_WIDTH;

}

else

{

textCol[i].Width = this.ColumnSizes[i];

}

textCol[i].ReadOnly = true;

}

this.TableStyles.Add(ts1);

}
Nov 15 '05 #1
1 1538
Never mind :) I'm not even going to tell you what I did wrong :) Stupid
mistake, has nothing to do with the class I wrote... It works fine... :)

"Saso Zagoranski" <sa*************@guest.arnes.si> wrote in message
news:bn**********@planja.arnes.si...
Hi!

I have extended the default windows.forms datagrid... I added a few options if the data is bound programmaticly... The main part of the function (the
for loop) loops through all the columns and creates a DataGridTextBoxColumn or DataGridBoolColumn for each of them...
The problem is, that the DataGrid always displays just one of the columns!
I have tried binding the DataTable after adding the TableStyle but that
didn't work... I have also tried
using the AddRange method and adding all of the columns at once but that
doesn't work either...
I really don't know what I'm doing wrong...

Any help?
Saso

Here is the code:

public void InitDataGrid(DataTable table)

{

this.DataBindings.Clear();

this.TableStyles.Clear();
this.SetDataBinding(table,"");
DataGridTableStyle ts1 = new DataGridTableStyle();

ts1.MappingName = "mainTable";

// Set other properties.

ts1.AlternatingBackColor = Color.AliceBlue;

DataGridColumnStyle[] textCol = new
DataGridColumnStyle[this.GridColumns.Length];

/* Add a GridColumnStyle and set its MappingName

to the name of a DataColumn in the DataTable.

Set the HeaderText and Width properties. */

for ( int i = 0;i < this.GridColumns.Length;i++ )

{

if ( ( this.ColumnTypes == null ) || (this.ColumnTypes.Length !=
this.GridColumns.Length) )

{

textCol[i] = new DataGridTextBoxColumn();

}

else

{

if ( this.ColumnTypes[i] == ColumnType.TextBox )

{

textCol[i] = new DataGridTextBoxColumn();

}

else

{

textCol[i] = new DataGridBoolColumn();

}

}
textCol[i].MappingName = this.GridColumns[i];
if ( (this.HeaderText == null ) || (this.HeaderText.Length !=
this.GridColumns.Length) )

{

textCol[i].HeaderText = this.GridColumns[i];

}

else

{

textCol[i].HeaderText = this.HeaderText[i];

}

if ( ( this.ColumnSizes == null ) || (this.ColumnSizes.Length !=
this.GridColumns.Length) )

{

textCol[i].Width = DEFAULT_WIDTH;

}

else

{

textCol[i].Width = this.ColumnSizes[i];

}

textCol[i].ReadOnly = true;

}

this.TableStyles.Add(ts1);

}

Nov 15 '05 #2

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

Similar topics

1
by: Vagabond Software | last post by:
I am creating a custom datagrid based, in part, from someone else's code. The author declared a derived datagrid class in a windows form, then declared a derived ColumnStyle class, in the same form,...
2
by: Jay Walker | last post by:
I created a custom DataGridColumn based on Marcie Robillard's MSDN Article: Creating Custom Columns for the ASP.NET Datagrid...
7
by: Girish | last post by:
OK.. phew. Playing with data grids for the past few days has been fun and a huge learning experience.. My problem. I have a requirement to display a gird with a gird. Within the embedded grid,...
1
by: Sam Samnah | last post by:
Hi Everyone. It has been a long time since my last post. Nevertheless, I have built a custom server control that allows a user to edit text, bolding, italics strike though table insertion and...
1
by: rn5a | last post by:
I have created a custom server control which is actually a Button clicking which prompts a user with a JavaScript confirm message asking him whether he would like to proceed or not. If he clicks...
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.