DataGrid Error - Need help
-
I have added a data grid. I am trying to change the default header of each column to another name. For example:
dgtsPayrollInfo.GridColumnStyles(0).HeaderText = "Employee ID"
dgtsPayrollInfo.GridColumnStyles(0).Alignment = HorizontalAlignment.CenterI keep getting an error. I want my first column to have employee id as the header. Any Sugggestion Thank you, ibok23
-
I have added a data grid. I am trying to change the default header of each column to another name. For example:
dgtsPayrollInfo.GridColumnStyles(0).HeaderText = "Employee ID"
dgtsPayrollInfo.GridColumnStyles(0).Alignment = HorizontalAlignment.CenterI keep getting an error. I want my first column to have employee id as the header. Any Sugggestion Thank you, ibok23
ibok23 wrote: I keep getting an error. And that error would be ....? RageInTheMachine9532
-
I have added a data grid. I am trying to change the default header of each column to another name. For example:
dgtsPayrollInfo.GridColumnStyles(0).HeaderText = "Employee ID"
dgtsPayrollInfo.GridColumnStyles(0).Alignment = HorizontalAlignment.CenterI keep getting an error. I want my first column to have employee id as the header. Any Sugggestion Thank you, ibok23
Dim GridTableStyle1 As New DataGridTableStyle() GridTableStyle1.MappingName = "Customer" 'Customer is the name of the table in the dataset Dim GridColStyle1 As New DataGridTextBoxColumn() With GridColStyle1 .HeaderText = "ID" .MappingName = "CustID" End With GridTableStyle1.GridColumnStyles.Add(GridColStyle1) MyDataGrid.TableStyles.Add(GridTableStyle1)
-
ibok23 wrote: I keep getting an error. And that error would be ....? RageInTheMachine9532
I am trying to put a header on each of my columns in my data grid. I have the columns already there, but with a different name from when I made the data relations. For example on column one it has "fldEmployeeId". I just want "Employee ID". I am getting an error while trying to run it. It is telling me that An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dllAdditional information: Index was out of range. Must be non-negative and less than the size of the collection. The error is on the first line in this part of the code. What am I doing wrong? I have a total of 6 columns. Any suggestions.
dgPayrollInfo.GridColumnStyles(0).HeaderText = "Employee ID"
dgPayrollInfo.GridColumnStyles(0).Alignment = HorizontalAlignment.Center
dgPayrollInfo.GridColumnStyles(1).HeaderText = "Payroll ID"
dgPayrollInfo.GridColumnStyles(1).Alignment = HorizontalAlignment.Center
dgPayrollInfo.GridColumnStyles(2).HeaderText = "Pay Date"
dgPayrollInfo.GridColumnStyles(2).Alignment = HorizontalAlignment.Center
dgPayrollInfo.GridColumnStyles(3).HeaderText = "Gross Pay"
dgPayrollInfo.GridColumnStyles(3).Alignment = HorizontalAlignment.Right
dgPayrollInfo.GridColumnStyles(4).HeaderText = "Withholding"
dgPayrollInfo.GridColumnStyles(4).Alignment = HorizontalAlignment.Right
dgPayrollInfo.GridColumnStyles(5).HeaderText = "Net Pay"
dgPayrollInfo.GridColumnStyles(5).Alignment = HorizontalAlignment.RightThank you, ibok23
-
I am trying to put a header on each of my columns in my data grid. I have the columns already there, but with a different name from when I made the data relations. For example on column one it has "fldEmployeeId". I just want "Employee ID". I am getting an error while trying to run it. It is telling me that An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dllAdditional information: Index was out of range. Must be non-negative and less than the size of the collection. The error is on the first line in this part of the code. What am I doing wrong? I have a total of 6 columns. Any suggestions.
dgPayrollInfo.GridColumnStyles(0).HeaderText = "Employee ID"
dgPayrollInfo.GridColumnStyles(0).Alignment = HorizontalAlignment.Center
dgPayrollInfo.GridColumnStyles(1).HeaderText = "Payroll ID"
dgPayrollInfo.GridColumnStyles(1).Alignment = HorizontalAlignment.Center
dgPayrollInfo.GridColumnStyles(2).HeaderText = "Pay Date"
dgPayrollInfo.GridColumnStyles(2).Alignment = HorizontalAlignment.Center
dgPayrollInfo.GridColumnStyles(3).HeaderText = "Gross Pay"
dgPayrollInfo.GridColumnStyles(3).Alignment = HorizontalAlignment.Right
dgPayrollInfo.GridColumnStyles(4).HeaderText = "Withholding"
dgPayrollInfo.GridColumnStyles(4).Alignment = HorizontalAlignment.Right
dgPayrollInfo.GridColumnStyles(5).HeaderText = "Net Pay"
dgPayrollInfo.GridColumnStyles(5).Alignment = HorizontalAlignment.RightThank you, ibok23
You need to create the GridColumnStyle first, then added it to the GridColumStylesCollection. Just indexing a GridColumnStyleCollection, like your doing, will not create a new column.
Dim newGridColumnStyle As New GridColumnStyle newGridColumnStyle.HeaderText = "Employee ID" newGridColumnStyle.Alignment = HorizontalAlignment.Center
dgPayrollInfo.GridColumnStyles.Add( newGridColumStyle )
.
.
.RageInTheMachine9532