472,954 Members | 1,902 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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 1525
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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
1
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.