G
Guest
Hi, I have the following code, that "should" display only one column on the datagrid from the datatable created here, but that is the theory anyway!,any comment on this would be appreicated...Thanks in advance
DataTable dtCompany = new DataTable("Company")
// Declare DataColumn and DataRow variables
DataColumn dcolCompanyCode
DataColumn dcolCompany
DataColumn dcolCompanyID
DataRow drowCompany
// Create new DataColumn, set DataType, ColumnName and add to DataTable.
dcolCompanyID = new DataColumn()
dcolCompanyID.DataType = System.Type.GetType("System.Int32")
dcolCompanyID.ColumnName = "CompanyID"
dtCompany.Columns.Add(dcolCompanyID)
// Create new DataColumn, set DataType, ColumnName and add to DataTable.
dcolCompanyCode = new DataColumn()
dcolCompanyCode.DataType = System.Type.GetType("System.String")
dcolCompanyCode.ColumnName = "CompanyCode"
dtCompany.Columns.Add(dcolCompanyCode)
// Create second column
dcolCompany = new DataColumn()
dcolCompany.DataType = Type.GetType("System.String")
dcolCompany.ColumnName = "CompanyName"
dtCompany.Columns.Add(dcolCompany)
// Create new DataRow objects and add to DataTable.
for(int i = 0; i < dsetCompanyDetails.Tables["Table"].Rows.Count; i++
drowCompany = dtCompany.NewRow()
drowCompany["CompanyCode"] = dsetCompanyDetails.Tables["Table"].Rows["CompanyCode"]
drowCompany["CompanyName"] = dsetCompanyDetails.Tables["Table"].Rows["CompanyName"]
dtCompany.Rows.Add(drowCompany)
this.dgrdCompanyDetails.DataSource = dtCompany
//this.dgrdCompanyDetails.DataSource=dsetCompanyDetails
DataGridTableStyle ts1 = new DataGridTableStyle()
ts1.MappingName = dtCompany.GetType().Name
//ts1.MappingName = "dtCompany"
DataGridTextBoxColumn dcolCustomerCode = new DataGridTextBoxColumn();// DataGridBoolColumn()
dcolCustomerCode.HeaderText = "Company Code"
dcolCustomerCode.MappingName = "CompanyCode"
dcolCustomerCode.Width = 150
ts1.GridColumnStyles.Add(dcolCustomerCode)
this.dgrdCompanyDetails..TableStyles.Add(ts1)
DataTable dtCompany = new DataTable("Company")
// Declare DataColumn and DataRow variables
DataColumn dcolCompanyCode
DataColumn dcolCompany
DataColumn dcolCompanyID
DataRow drowCompany
// Create new DataColumn, set DataType, ColumnName and add to DataTable.
dcolCompanyID = new DataColumn()
dcolCompanyID.DataType = System.Type.GetType("System.Int32")
dcolCompanyID.ColumnName = "CompanyID"
dtCompany.Columns.Add(dcolCompanyID)
// Create new DataColumn, set DataType, ColumnName and add to DataTable.
dcolCompanyCode = new DataColumn()
dcolCompanyCode.DataType = System.Type.GetType("System.String")
dcolCompanyCode.ColumnName = "CompanyCode"
dtCompany.Columns.Add(dcolCompanyCode)
// Create second column
dcolCompany = new DataColumn()
dcolCompany.DataType = Type.GetType("System.String")
dcolCompany.ColumnName = "CompanyName"
dtCompany.Columns.Add(dcolCompany)
// Create new DataRow objects and add to DataTable.
for(int i = 0; i < dsetCompanyDetails.Tables["Table"].Rows.Count; i++
drowCompany = dtCompany.NewRow()
drowCompany["CompanyCode"] = dsetCompanyDetails.Tables["Table"].Rows["CompanyCode"]
drowCompany["CompanyName"] = dsetCompanyDetails.Tables["Table"].Rows["CompanyName"]
dtCompany.Rows.Add(drowCompany)
this.dgrdCompanyDetails.DataSource = dtCompany
//this.dgrdCompanyDetails.DataSource=dsetCompanyDetails
DataGridTableStyle ts1 = new DataGridTableStyle()
ts1.MappingName = dtCompany.GetType().Name
//ts1.MappingName = "dtCompany"
DataGridTextBoxColumn dcolCustomerCode = new DataGridTextBoxColumn();// DataGridBoolColumn()
dcolCustomerCode.HeaderText = "Company Code"
dcolCustomerCode.MappingName = "CompanyCode"
dcolCustomerCode.Width = 150
ts1.GridColumnStyles.Add(dcolCustomerCode)
this.dgrdCompanyDetails..TableStyles.Add(ts1)