DataGrid TableMapping and column ordering

G

Guest

Hello all,

I have been trying to figure out just what I am doing
wrong. Here is the situation.

I have a StronglyTyped Collection class called
AccountsList that derives from CollectionBase. It's full
name
is: 'ServiceLink.QA.Business.QaPrototype.AccountsList' It
contains a list of Accounts defined
as 'ServiceLink.QA.Business.QaPrototype.BankAccount'.
Accounts have public properties like:
BankName
BankID
BankAccountNumber
AccountOwner
etc.

What I am trying to do is to create a DataGridTableStyle
mapping with column mappings to define the display
characteristisc of the columns and the order in which they
show up in the datagrid.

So far it does not work. The columns appear in the order
that the grid determines not in the order I am trying to
display them.

Here is the code I am using:
What is wrong.

// create a DataView of the
correct accounts
try
{
AccountsList alist =
bank.Accounts;

if (alist.Count > 0)
{

if
(this.grdAccounts.TableStyles.Count == 0)
{


/* Create
a new DataGridTableStyle and set
its
MappingName to the TableName of a DataTable. */

DataGridTableStyle ts1 = new DataGridTableStyle();

ts1.MappingName
= "ServiceLink.QA.Business.QaPrototype.AccountsList[]";


DataGridColumnStyle colStyle;


/* Add a
GridColumnStyle and set its MappingName
to the
name of a DataColumn in the DataTable.
Set the
HeaderText and Width properties. */

colStyle =
new DataGridTextBoxColumn();

colStyle.MappingName = "BankAccountID";

colStyle.HeaderText = "";

colStyle.Width = 0;

ts1.GridColumnStyles.Add(colStyle);

colStyle =
new DataGridTextBoxColumn();

colStyle.MappingName = "BankID";

colStyle.HeaderText = "";

colStyle.Width = 0;

ts1.GridColumnStyles.Add(colStyle);

colStyle =
new DataGridTextBoxColumn();

colStyle.MappingName = "BankAccountDescr";

colStyle.HeaderText = "Account Description";

colStyle.Width = 250;

ts1.GridColumnStyles.Add(colStyle);

colStyle =
new DataGridTextBoxColumn();

colStyle.MappingName = "BankAccountNumber";

colStyle.HeaderText = "Account Number";

colStyle.Width = 250;

ts1.GridColumnStyles.Add(colStyle);


colStyle =
new DataGridTextBoxColumn();

colStyle.MappingName = "State";

colStyle.HeaderText = "State";

colStyle.Width = 50;

ts1.GridColumnStyles.Add(colStyle);

colStyle =
new DataGridTextBoxColumn();

colStyle.MappingName = "LastDepositNum";

colStyle.HeaderText = "Last Deposit";

colStyle.Width = 50;

ts1.GridColumnStyles.Add(colStyle);

colStyle =
new DataGridTextBoxColumn();

colStyle.MappingName = "LastDepositTicketNum";

colStyle.HeaderText = "Deposit Ticket";

colStyle.Width = 50;

ts1.GridColumnStyles.Add(colStyle);

colStyle =
new DataGridTextBoxColumn();

colStyle.MappingName = "LastCheckNum";

colStyle.HeaderText = "Last Check";

colStyle.Width = 50;

ts1.GridColumnStyles.Add(colStyle);

colStyle =
new DataGridTextBoxColumn();

colStyle.MappingName = "BankAccountStatusTypeID";

colStyle.HeaderText = "Status ID";

colStyle.Width = 50;

ts1.GridColumnStyles.Add(colStyle);

colStyle =
new DataGridTextBoxColumn();

colStyle.MappingName = "IsGeneralAccount";

colStyle.HeaderText = "Gen. Accnt.";

colStyle.Width = 50;

ts1.GridColumnStyles.Add(colStyle);

colStyle =
new DataGridTextBoxColumn();

colStyle.MappingName = "IsSuspenseAccount";

colStyle.HeaderText = "Susp. Accnt.";

colStyle.Width = 50;

ts1.GridColumnStyles.Add(colStyle);


colStyle =
new DataGridTextBoxColumn();

colStyle.MappingName = "IsAutoCheck";

colStyle.HeaderText = "Auto Check";

colStyle.Width = 50;

ts1.GridColumnStyles.Add(colStyle);


colStyle =
new DataGridTextBoxColumn();

colStyle.MappingName = "MICRCode";

colStyle.HeaderText = "MICR Code";

colStyle.Width = 150;

ts1.GridColumnStyles.Add(colStyle);

colStyle =
new DataGridTextBoxColumn();

colStyle.MappingName = "AccountOwner";

colStyle.HeaderText = "Owner";

colStyle.Width = 250;

ts1.GridColumnStyles.Add(colStyle);

colStyle =
new DataGridTextBoxColumn();

colStyle.MappingName = "SSN";

colStyle.HeaderText = "SSN";

colStyle.Width = 100;

ts1.GridColumnStyles.Add(colStyle);

colStyle =
new DataGridTextBoxColumn();

colStyle.MappingName = "DateOpened";

colStyle.HeaderText = "Opened";

colStyle.Width = 250;

ts1.GridColumnStyles.Add(colStyle);

colStyle =
new DataGridTextBoxColumn();

colStyle.MappingName = "LastActivity";

colStyle.HeaderText = "Last Activ.";

colStyle.Width = 150;

ts1.GridColumnStyles.Add(colStyle);

colStyle =
new DataGridTextBoxColumn();

colStyle.MappingName = "ActivityCode";

colStyle.HeaderText = "Activ. Code";

colStyle.Width = 150;

ts1.GridColumnStyles.Add(colStyle);

colStyle =
new DataGridTextBoxColumn();

colStyle.MappingName = "AverageBal";

colStyle.HeaderText = "Avg. Bal.";

colStyle.Width = 150;

ts1.GridColumnStyles.Add(colStyle);

colStyle =
new DataGridTextBoxColumn();

colStyle.MappingName = "CurrenBal";

colStyle.HeaderText = "Cur. Bal.";

colStyle.Width = 150;

ts1.GridColumnStyles.Add(colStyle);


this.grdAccounts.TableStyles.Add(ts1);

}


this.grdAccounts.Enabled = true;

this.grdAccounts.DataSource=alist;


this.grdAccounts.Select(0);
//string
bankAccountID = this.grdAccounts
[this.grdAccounts.CurrentRowIndex,0].ToString();
string
bankAccountID = this.grdAccounts
[this.grdAccounts.CurrentRowIndex,12].ToString();


this.displayAccountDetails(bank.BankName,
bankAccountID);
}
else
{

this.grdAccounts.Enabled = false;
}
}
catch
(System.Data.EvaluateException evEx)
{
MessageBox.Show
(String.Format("We aparantly have a problem with the
BankID for the currently selected bank. It is probably
null, exception text is: {0}", evEx.Message));
this.grdAccounts.Enabled =
false;
}



Thanks,

Gary
 
C

ClayB [Syncfusion]

This may be a MappingName problem. Here is a FAQ that has code that will
show exactly the string you need to use for your datasource.

George Shepherd's Windows Forms FAQ contains an entry entitled:

How do I determine the DataGridTableStyle MappingName that should used
for a DataGrid to make sure the grid uses my tablestyle ?

Check it out at:
http://www.syncfusion.com/faq/winforms/search/931.asp

=============================================
Clay Burch, MVP

Syncfusion, Inc.
visit http://www.syncfusion.com for .NET Essentials




Hello all,

I have been trying to figure out just what I am doing
wrong. Here is the situation.

I have a StronglyTyped Collection class called
AccountsList that derives from CollectionBase. It's full
name
is: 'ServiceLink.QA.Business.QaPrototype.AccountsList' It
contains a list of Accounts defined
as 'ServiceLink.QA.Business.QaPrototype.BankAccount'.
Accounts have public properties like:
BankName
BankID
BankAccountNumber
AccountOwner
etc.

What I am trying to do is to create a DataGridTableStyle
mapping with column mappings to define the display
characteristisc of the columns and the order in which they
show up in the datagrid.

So far it does not work. The columns appear in the order
that the grid determines not in the order I am trying to
display them.

Here is the code I am using:
What is wrong.

// create a DataView of the
correct accounts
try
{
AccountsList alist =
bank.Accounts;

if (alist.Count > 0)
{

if
(this.grdAccounts.TableStyles.Count == 0)
{


/* Create
a new DataGridTableStyle and set
its
MappingName to the TableName of a DataTable. */

DataGridTableStyle ts1 = new DataGridTableStyle();

ts1.MappingName
= "ServiceLink.QA.Business.QaPrototype.AccountsList[]";


DataGridColumnStyle colStyle;


/* Add a
GridColumnStyle and set its MappingName
to the
name of a DataColumn in the DataTable.
Set the
HeaderText and Width properties. */

colStyle =
new DataGridTextBoxColumn();

colStyle.MappingName = "BankAccountID";

colStyle.HeaderText = "";

colStyle.Width = 0;

ts1.GridColumnStyles.Add(colStyle);

colStyle =
new DataGridTextBoxColumn();

colStyle.MappingName = "BankID";

colStyle.HeaderText = "";

colStyle.Width = 0;

ts1.GridColumnStyles.Add(colStyle);

colStyle =
new DataGridTextBoxColumn();

colStyle.MappingName = "BankAccountDescr";

colStyle.HeaderText = "Account Description";

colStyle.Width = 250;

ts1.GridColumnStyles.Add(colStyle);

colStyle =
new DataGridTextBoxColumn();

colStyle.MappingName = "BankAccountNumber";

colStyle.HeaderText = "Account Number";

colStyle.Width = 250;

ts1.GridColumnStyles.Add(colStyle);


colStyle =
new DataGridTextBoxColumn();

colStyle.MappingName = "State";

colStyle.HeaderText = "State";

colStyle.Width = 50;

ts1.GridColumnStyles.Add(colStyle);

colStyle =
new DataGridTextBoxColumn();

colStyle.MappingName = "LastDepositNum";

colStyle.HeaderText = "Last Deposit";

colStyle.Width = 50;

ts1.GridColumnStyles.Add(colStyle);

colStyle =
new DataGridTextBoxColumn();

colStyle.MappingName = "LastDepositTicketNum";

colStyle.HeaderText = "Deposit Ticket";

colStyle.Width = 50;

ts1.GridColumnStyles.Add(colStyle);

colStyle =
new DataGridTextBoxColumn();

colStyle.MappingName = "LastCheckNum";

colStyle.HeaderText = "Last Check";

colStyle.Width = 50;

ts1.GridColumnStyles.Add(colStyle);

colStyle =
new DataGridTextBoxColumn();

colStyle.MappingName = "BankAccountStatusTypeID";

colStyle.HeaderText = "Status ID";

colStyle.Width = 50;

ts1.GridColumnStyles.Add(colStyle);

colStyle =
new DataGridTextBoxColumn();

colStyle.MappingName = "IsGeneralAccount";

colStyle.HeaderText = "Gen. Accnt.";

colStyle.Width = 50;

ts1.GridColumnStyles.Add(colStyle);

colStyle =
new DataGridTextBoxColumn();

colStyle.MappingName = "IsSuspenseAccount";

colStyle.HeaderText = "Susp. Accnt.";

colStyle.Width = 50;

ts1.GridColumnStyles.Add(colStyle);


colStyle =
new DataGridTextBoxColumn();

colStyle.MappingName = "IsAutoCheck";

colStyle.HeaderText = "Auto Check";

colStyle.Width = 50;

ts1.GridColumnStyles.Add(colStyle);


colStyle =
new DataGridTextBoxColumn();

colStyle.MappingName = "MICRCode";

colStyle.HeaderText = "MICR Code";

colStyle.Width = 150;

ts1.GridColumnStyles.Add(colStyle);

colStyle =
new DataGridTextBoxColumn();

colStyle.MappingName = "AccountOwner";

colStyle.HeaderText = "Owner";

colStyle.Width = 250;

ts1.GridColumnStyles.Add(colStyle);

colStyle =
new DataGridTextBoxColumn();

colStyle.MappingName = "SSN";

colStyle.HeaderText = "SSN";

colStyle.Width = 100;

ts1.GridColumnStyles.Add(colStyle);

colStyle =
new DataGridTextBoxColumn();

colStyle.MappingName = "DateOpened";

colStyle.HeaderText = "Opened";

colStyle.Width = 250;

ts1.GridColumnStyles.Add(colStyle);

colStyle =
new DataGridTextBoxColumn();

colStyle.MappingName = "LastActivity";

colStyle.HeaderText = "Last Activ.";

colStyle.Width = 150;

ts1.GridColumnStyles.Add(colStyle);

colStyle =
new DataGridTextBoxColumn();

colStyle.MappingName = "ActivityCode";

colStyle.HeaderText = "Activ. Code";

colStyle.Width = 150;

ts1.GridColumnStyles.Add(colStyle);

colStyle =
new DataGridTextBoxColumn();

colStyle.MappingName = "AverageBal";

colStyle.HeaderText = "Avg. Bal.";

colStyle.Width = 150;

ts1.GridColumnStyles.Add(colStyle);

colStyle =
new DataGridTextBoxColumn();

colStyle.MappingName = "CurrenBal";

colStyle.HeaderText = "Cur. Bal.";

colStyle.Width = 150;

ts1.GridColumnStyles.Add(colStyle);


this.grdAccounts.TableStyles.Add(ts1);

}


this.grdAccounts.Enabled = true;

this.grdAccounts.DataSource=alist;


this.grdAccounts.Select(0);
//string
bankAccountID = this.grdAccounts
[this.grdAccounts.CurrentRowIndex,0].ToString();
string
bankAccountID = this.grdAccounts
[this.grdAccounts.CurrentRowIndex,12].ToString();


this.displayAccountDetails(bank.BankName,
bankAccountID);
}
else
{

this.grdAccounts.Enabled = false;
}
}
catch
(System.Data.EvaluateException evEx)
{
MessageBox.Show
(String.Format("We aparantly have a problem with the
BankID for the currently selected bank. It is probably
null, exception text is: {0}", evEx.Message));
this.grdAccounts.Enabled =
false;
}



Thanks,

Gary
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top