Unable to create Datagrid table style.

mcutchin

New member
Joined
Jul 6, 2005
Messages
2
Programming Experience
3-5
I am using the code below to create a table style for my data grid. Yet when I execute the code the data displays without applying the table style. Any ideas on what I can do in order to bind the table style to my data grid?

Thanks...

VB.NET:
 [size=2][color=#0000ff]
Private[/color][/size][size=2][color=#0000ff]Sub[/color][/size][size=2] Form1_Load([/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] sender [/size][size=2][color=#0000ff]As[/color][/size][size=2] System.Object, [/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] e [/size][size=2][color=#0000ff]As[/color][/size][size=2] System.EventArgs) [/size][size=2][color=#0000ff]Handles[/color][/size][size=2][color=#0000ff]MyBase[/color][/size][size=2].Load
 
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] datCustInfoSetPyAr [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]New[/color][/size][size=2] DataSet
 
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] datCustInfoSetDiscNot [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]New[/color][/size][size=2] DataSet
 
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] cmdPyAr [/size][size=2][color=#0000ff]As[/color][/size][size=2] OracleCommand = [/size][size=2][color=#0000ff]New[/color][/size][size=2] OracleCommand _
 
("Select TYPE as Type, AMT_DUE AS AmountDue,DATE_DUE AS DueDate, DATE_PAID AS DatePaid From Payment" _
 
+ " Where Cust_Nbr = TO_NUMBER (SUBSTR('" + txtAccount.Text + "',1,6)) AND Location_Code = SUBSTR('" + txtAccount.Text + "',7,6))", conn)
 
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] cmdDiscNot [/size][size=2][color=#0000ff]As[/color][/size][size=2] OracleCommand = [/size][size=2][color=#0000ff]New[/color][/size][size=2] OracleCommand _
 
("Select DISCONNECT_AMT as DisconnectAmt, DISCONNECT_DATE AS FieldDate, PAST_DUE AS DueNow From BILL_HISTORY" _
 
+ "Where Cust_Nbr = TO_NUMBER (SUBSTR('" + txtAccount.Text + "',1,6)) AND Location_Code = SUBSTR('" + txtAccount.Text + "',7,6))", conn)
 
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] OracleDataAdapterDisc [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]New[/color][/size][size=2] OracleClient.OracleDataAdapter(cmdDiscNot)
 
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] OracleDataAdapterPymtArg [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]New[/color][/size][size=2] OracleClient.OracleDataAdapter(cmdPyAr)
 
OracleDataAdapterDisc.Fill(datCustInfoSetDiscNot, 0)
 
OracleDataAdapterPymtArg.Fill(datCustInfoSetPyAr, 0)
 
[/size][size=2][color=#0000ff]If[/color][/size][size=2] datCustInfoSetDiscNot.Tables(0).Rows.Count > 1 [/size][size=2][color=#0000ff]Then[/color][/size][size=2] datDisconnect.Visible = [/size][size=2][color=#0000ff]True
 
[/color][/size][size=2][color=#0000ff]If[/color][/size][size=2] datCustInfoSetPyAr.Tables(0).Rows.Count > 0 [/size][size=2][color=#0000ff]Then[/color][/size][size=2] datPaymentArrangement.Visible = [/size][size=2][color=#0000ff]True
 
[/color][/size][size=2][color=#008000]'Add Boolean column to Disconnect datatable
 
[/color][/size][size=2][color=#0000ff]Dim[/color][/size][size=2] cDisconnect [/size][size=2][color=#0000ff]As[/color][/size][size=2] DataColumn = [/size][size=2][color=#0000ff]New[/color][/size][size=2] DataColumn("Select", [/size][size=2][color=#0000ff]GetType[/color][/size][size=2]([/size][size=2][color=#0000ff]Boolean[/color][/size][size=2]))
 
cDisconnect.DefaultValue = [/size][size=2][color=#0000ff]False
 
[/color][/size][size=2]datCustInfoSetDiscNot.Tables(0).Columns.Add(cDisconnect)
 
[/size][size=2][color=#008000]'Add Boolean column to PymtArg datatable
 
[/color][/size][size=2][color=#0000ff]Dim[/color][/size][size=2] cPymtArg [/size][size=2][color=#0000ff]As[/color][/size][size=2] DataColumn = [/size][size=2][color=#0000ff]New[/color][/size][size=2] DataColumn("SelectPmt", [/size][size=2][color=#0000ff]GetType[/color][/size][size=2]([/size][size=2][color=#0000ff]Boolean[/color][/size][size=2]))
 
cPymtArg.DefaultValue = [/size][size=2][color=#0000ff]False
 
[/color][/size][size=2]datCustInfoSetPyAr.Tables(0).Columns.Add(cPymtArg)
 
[/size][size=2][color=#008000]'Make it so that new row doesn't appear at bottom of datagrid
 
[/color][/size][size=2][color=#0000ff]Dim[/color][/size][size=2] DiscDataView [/size][size=2][color=#0000ff]As[/color][/size][size=2] DataView = [/size][size=2][color=#0000ff]New[/color][/size][size=2] DataView(datCustInfoSetDiscNot.Tables(0))
 
DiscDataView.AllowDelete = [/size][size=2][color=#0000ff]False
 
[/color][/size][size=2]DiscDataView.AllowNew = [/size][size=2][color=#0000ff]False
 
[/color][/size][size=2]datDisconnect.DataSource = DiscDataView
 
[/size][size=2][color=#008000]'Make it so that new row doesn't appear at bottom of datagrid
 
[/color][/size][size=2][color=#0000ff]Dim[/color][/size][size=2] PymtArgDataView [/size][size=2][color=#0000ff]As[/color][/size][size=2] DataView = [/size][size=2][color=#0000ff]New[/color][/size][size=2] DataView(datCustInfoSetPyAr.Tables(0))
 
PymtArgDataView.AllowDelete = [/size][size=2][color=#0000ff]False
 
[/color][/size][size=2]PymtArgDataView.AllowNew = [/size][size=2][color=#0000ff]False
 
[/color][/size][size=2][color=#008000]'datPaymentArrangement.DataSource = datCustInfoSetPyAr
 
[/color][/size][size=2]datPaymentArrangement.DataSource = PymtArgDataView
 
[/size][size=2][color=#008000]'Step 1: Create a DataGridTableStyle & 
 
[/color][/size][size=2][color=#008000]' set mappingname to table.
 
[/color][/size][size=2][color=#0000ff]Dim[/color][/size][size=2] DisconnectTableStyle [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]New[/color][/size][size=2] DataGridTableStyle
 
DisconnectTableStyle.MappingName = "Disconnect"
 
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] PaymentArrangementTableStyle [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]New[/color][/size][size=2] DataGridTableStyle
 
PaymentArrangementTableStyle.MappingName = "PaymentArrangement"
 
[/size][size=2][color=#008000]'Step 2: Create DataGridColumnStyle for each col 
 
[/color][/size][size=2][color=#008000]' we want to see in the grid and in the 
 
[/color][/size][size=2][color=#008000]' order that we want to see them.
 
[/color][/size][size=2][color=#008000]'Disconnect Amount. (Disconnect)
 
[/color][/size][size=2][color=#0000ff]Dim[/color][/size][size=2] CheckBox [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]New[/color][/size][size=2] DataGridBoolColumn
 
CheckBox.MappingName = "Select"
 
CheckBox.HeaderText = ""
 
CheckBox.Width = 30
 
[/size][size=2][color=#008000]'turn off tristate
 
[/color][/size][size=2]CheckBox.AllowNull = [/size][size=2][color=#0000ff]False
 
[/color][/size][size=2]DisconnectTableStyle.GridColumnStyles.Add(CheckBox)
 
[/size][size=2][color=#008000]'Arrangement Amount. (Payment Arrangement)
 
[/color][/size][size=2][color=#0000ff]Dim[/color][/size][size=2] pmtCheckBox [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]New[/color][/size][size=2] DataGridBoolColumn
 
pmtCheckBox.MappingName = "SelectPmt"
 
pmtCheckBox.HeaderText = ""
 
pmtCheckBox.Width = 30
 
[/size][size=2][color=#008000]'turn off tristate
 
[/color][/size][size=2]pmtCheckBox.AllowNull = [/size][size=2][color=#0000ff]False
 
[/color][/size][size=2]PaymentArrangementTableStyle.GridColumnStyles.Add(pmtCheckBox)
 
[/size][size=2][color=#008000]'Step 2: DisconnectAmount (Disconnect)
 
[/color][/size][size=2][color=#0000ff]Dim[/color][/size][size=2] column [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]New[/color][/size][size=2] DataGridTextBoxColumn
 
column.MappingName = "DisconnectAmt"
 
column.HeaderText = "DiscAmt"
 
column.Width = 50
 
column.ReadOnly = [/size][size=2][color=#0000ff]True
 
[/color][/size][size=2]DisconnectTableStyle.GridColumnStyles.Add(column)
 
[/size][size=2][color=#008000]'Step 2: Payment Arrangement Type (PaymentArrangement)
 
[/color][/size][size=2]column = [/size][size=2][color=#0000ff]New[/color][/size][size=2] DataGridTextBoxColumn
 
column.MappingName = "Type"
 
column.HeaderText = "Type"
 
column.Width = 50
 
column.ReadOnly = [/size][size=2][color=#0000ff]True
 
[/color][/size][size=2]PaymentArrangementTableStyle.GridColumnStyles.Add(column)
 
[/size][size=2][color=#008000]'Step 2: Field Date (Disconnect)
 
[/color][/size][size=2]column = [/size][size=2][color=#0000ff]New[/color][/size][size=2] DataGridTextBoxColumn
 
column.MappingName = "FieldDate"
 
column.HeaderText = "FieldDate"
 
column.Width = 60
 
column.ReadOnly = [/size][size=2][color=#0000ff]True
 
[/color][/size][size=2]DisconnectTableStyle.GridColumnStyles.Add(column)
 
[/size][size=2][color=#008000]'Step 2: Amount Due (PaymentArrangement)
 
[/color][/size][size=2]column = [/size][size=2][color=#0000ff]New[/color][/size][size=2] DataGridTextBoxColumn
 
column.MappingName = "AmountDue"
 
column.HeaderText = "AmtDue"
 
column.Width = 50
 
column.ReadOnly = [/size][size=2][color=#0000ff]True
 
[/color][/size][size=2]PaymentArrangementTableStyle.GridColumnStyles.Add(column)
 
[/size][size=2][color=#008000]'Step 2: Due Now (Disconnect)
 
[/color][/size][size=2]column = [/size][size=2][color=#0000ff]New[/color][/size][size=2] DataGridTextBoxColumn
 
column.MappingName = "DueNow"
 
column.HeaderText = "DueNow"
 
column.Width = 50
 
column.ReadOnly = [/size][size=2][color=#0000ff]True
 
[/color][/size][size=2]DisconnectTableStyle.GridColumnStyles.Add(column)
 
[/size][size=2][color=#008000]'Step 2: Due Date (PaymentArrangement)
 
[/color][/size][size=2]column = [/size][size=2][color=#0000ff]New[/color][/size][size=2] DataGridTextBoxColumn
 
column.MappingName = "DueDate"
 
column.HeaderText = "DueDate"
 
column.Width = 60
 
column.ReadOnly = [/size][size=2][color=#0000ff]True
 
[/color][/size][size=2]PaymentArrangementTableStyle.GridColumnStyles.Add(column)
 
[/size][size=2][color=#008000]'Step 3: Add the tablestyle to the datagrid
 
[/color][/size][size=2][color=#0000ff]Me[/color][/size][size=2].datDisconnect.TableStyles.Add(DisconnectTableStyle)
 
[/size][size=2][color=#0000ff]Me[/color][/size][size=2].datPaymentArrangement.TableStyles.Add(PaymentArrangementTableStyle)
[/size][size=2]
[/size][size=2][color=#0000ff]End[/color][/size][size=2][color=#0000ff]Sub
 
[/color][/size]
 
Back
Top