I have a datagrid where I am trying to align some columns to the center. The
rest should be aligned to the right. When I try the code below I get an
error message saying that the index is out of bounds. When debugging I get
the column count of the datagrid to be 1. I find this rather ridiculous only
because there are 61 columns that I can physically see. :) Plus, the data
table that I am using to bind the datagrid has a count of 61. Could someone
please take a look at the code below to see what I am missing, if I am
missing anything? I appreciate any help.
Thanks,
Jennifer
Private Sub FillGrid(ByVal SortExp As String)
Dim dvMain As DataView
Dim X As Int64
Dim dtMain As New DataTable()
Dim DR As DataRow
Dim Update_User As String
If txtStartDate.Text <> "*" Then
If txtEndDate.Text = "*" Then Exit Sub
End If
dvMain = GetDailySales(txtUnitID.Text, txtStartDate.Text, txtEndDate.Text)
If SortExp <> "" Then
dvMain.Sort = SortExp
End If
Dim Col1, Col2, Col3, Col4, Col5, Col6, Col7, Col8, Col9, Col10 As String
Dim Col11, Col12, Col13, Col14, Col15, Col16, Col17, Col18, Col19, Col20
As String
Dim Col21, Col22, Col23, Col24, Col25, Col26, Col27, Col28, Col29, Col30
As String
Dim Col31, Col32, Col33, Col34, Col35, Col36, Col37, Col38, Col39, Col40
As String
Dim Col41, Col42, Col43, Col44, Col45, Col46, Col47, Col48, Col49, Col50,
Col51, Col52 As String
Dim Col53, Col54, Col55, Col56, Col57, Col58, Col59, Col60, Col61 As String
Col1 = "Unit"
Col2 = "Date"
Col3 = "Status"
Col4 = "Deposit" & vbCrLf & "Evening" & vbCrLf & "$"
Col55 = "Deposit" & vbCrLf & "Evening" & vbCrLf & "$" & vbCrLf & "Verified"
Col5 = "Deposit" & vbCrLf & "Early_Bird" & vbCrLf & "$"
'-----more column names set here------------
dtMain.Columns.Add(Col1)
dtMain.Columns.Add(Col2)
dtMain.Columns.Add(Col3)
dtMain.Columns.Add(Col4)
If chkViewVerif.Checked = True Then dtMain.Columns.Add(Col55)
'-----adding the rest of the columns to the data row here
Dim BD As Date
For X = 0 To dvMain.Count - 1
DR = dtMain.NewRow
DR(Col1) = dvMain(X)("Unit_ID")
BD = dvMain(X)("Business_Date")
DR(Col2) = BD.ToShortDateString
DR(Col3) = dvMain(X)("Status")
If IsDBNull(dvMain(X)("User_ID")) Then
DR(Col50) = dvMain(X)("User_ID")
Else
Update_User = dvMain(X)("User_ID")
DR(Col50) = Update_User.Substring(12)
End If
DR(Col4) = Format(dvMain(X)("Deposit_Eve_Amt"), "N")
If chkViewVerif.Checked = True Then DR(Col55) =
dvMain(X)("Deposit_Eve_Amt_Verified")
'--- assigning the rest of the values here
dtMain.Rows.Add(DR)
Next
dgDSR.DataSource = dtMain
dgDSR.DataBind()
'---trying to align a column here (and it doesn't work)
dgDSR.Columns(2).ItemStyle.HorizontalAlign = HorizontalAlign.Center
End Sub 1 1304
Well, I still don't get why original code posted does not work, but if anyone
else has run into the same situation, I found the following code will work.
My thanks to Greg O. who posted at http://www.dotnet247.com/247referenc...25/125572.aspx
Dim tablerowitem As System.Web.UI.WebControls.DataGridItem
tablerowitem = dgDSR.Controls(0).Controls(0)
For Each tablerowitem In dgDSR.Items
tablerowitem.Cells(3).HorizontalAlign = HorizontalAlign.Center
If chkViewVerif.Checked = True Then
tablerowitem.Cells(5).HorizontalAlign = HorizontalAlign.Center
tablerowitem.Cells(7).HorizontalAlign = HorizontalAlign.Center
tablerowitem.Cells(9).HorizontalAlign = HorizontalAlign.Center
tablerowitem.Cells(11).HorizontalAlign = HorizontalAlign.Center
tablerowitem.Cells(14).HorizontalAlign = HorizontalAlign.Center
tablerowitem.Cells(16).HorizontalAlign = HorizontalAlign.Center
tablerowitem.Cells(18).HorizontalAlign = HorizontalAlign.Center
tablerowitem.Cells(20).HorizontalAlign = HorizontalAlign.Center
tablerowitem.Cells(22).HorizontalAlign = HorizontalAlign.Center
End If
Next
"Jennifer" wrote: I have a datagrid where I am trying to align some columns to the center. The rest should be aligned to the right. When I try the code below I get an error message saying that the index is out of bounds. When debugging I get the column count of the datagrid to be 1. I find this rather ridiculous only because there are 61 columns that I can physically see. :) Plus, the data table that I am using to bind the datagrid has a count of 61. Could someone please take a look at the code below to see what I am missing, if I am missing anything? I appreciate any help.
Thanks, Jennifer Private Sub FillGrid(ByVal SortExp As String) Dim dvMain As DataView Dim X As Int64 Dim dtMain As New DataTable() Dim DR As DataRow Dim Update_User As String If txtStartDate.Text <> "*" Then If txtEndDate.Text = "*" Then Exit Sub End If dvMain = GetDailySales(txtUnitID.Text, txtStartDate.Text, txtEndDate.Text) If SortExp <> "" Then dvMain.Sort = SortExp End If Dim Col1, Col2, Col3, Col4, Col5, Col6, Col7, Col8, Col9, Col10 As String Dim Col11, Col12, Col13, Col14, Col15, Col16, Col17, Col18, Col19, Col20 As String Dim Col21, Col22, Col23, Col24, Col25, Col26, Col27, Col28, Col29, Col30 As String Dim Col31, Col32, Col33, Col34, Col35, Col36, Col37, Col38, Col39, Col40 As String Dim Col41, Col42, Col43, Col44, Col45, Col46, Col47, Col48, Col49, Col50, Col51, Col52 As String Dim Col53, Col54, Col55, Col56, Col57, Col58, Col59, Col60, Col61 As String
Col1 = "Unit" Col2 = "Date" Col3 = "Status" Col4 = "Deposit" & vbCrLf & "Evening" & vbCrLf & "$" Col55 = "Deposit" & vbCrLf & "Evening" & vbCrLf & "$" & vbCrLf & "Verified" Col5 = "Deposit" & vbCrLf & "Early_Bird" & vbCrLf & "$" '-----more column names set here------------
dtMain.Columns.Add(Col1) dtMain.Columns.Add(Col2) dtMain.Columns.Add(Col3) dtMain.Columns.Add(Col4) If chkViewVerif.Checked = True Then dtMain.Columns.Add(Col55) '-----adding the rest of the columns to the data row here
Dim BD As Date For X = 0 To dvMain.Count - 1 DR = dtMain.NewRow DR(Col1) = dvMain(X)("Unit_ID") BD = dvMain(X)("Business_Date") DR(Col2) = BD.ToShortDateString DR(Col3) = dvMain(X)("Status") If IsDBNull(dvMain(X)("User_ID")) Then DR(Col50) = dvMain(X)("User_ID") Else Update_User = dvMain(X)("User_ID") DR(Col50) = Update_User.Substring(12) End If DR(Col4) = Format(dvMain(X)("Deposit_Eve_Amt"), "N") If chkViewVerif.Checked = True Then DR(Col55) = dvMain(X)("Deposit_Eve_Amt_Verified") '--- assigning the rest of the values here dtMain.Rows.Add(DR) Next
dgDSR.DataSource = dtMain dgDSR.DataBind()
'---trying to align a column here (and it doesn't work) dgDSR.Columns(2).ItemStyle.HorizontalAlign = HorizontalAlign.Center
End Sub This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: John Smith |
last post by:
Hey folks,
Got a Windows Form DataGrid that I bind to a dataset. Using the Table
Styles and the Grid Column Styles, I tell it to right align the columns
which have a numeric value (like Excel...
|
by: Amber |
last post by:
The DataGrid allows you to make columns visible or invisible on demand
- even edit and other special columns. This article will show you how
it is done.
Some developers have reported problems...
|
by: Dave |
last post by:
Hello all,
I need to know if you can vertically align Items within an
ItemTemplate. For example I have two columns, one column
has a stack of 6 textboxes, my second column can have 1 to
n...
|
by: Jim Heavey |
last post by:
Trying to figure out the technique which should be used
to add rows to a datagrid. I am thinking that I would
want an "Add" button on the footer, but I am not quite
sure how to do that. Is that...
|
by: tshad |
last post by:
I am having trouble with links in my DataGrid.
I have Links all over my page set to smaller and they are consistant all
over the page in both Mozilla and IE, except for the DataGrid.
Here is a...
| |
by: CSL |
last post by:
I am using the DataGrid in a Windows Application, how can
I adjust the widths of each column individually.
|
by: nemo |
last post by:
I'm creating a datasource and populating a datagrid at runtime. The
code is as follows:
dt = New DataTable
dt.Columns.Add(New DataColumn("Item", GetType(String)))
dt.Columns.Add(New...
|
by: Linux Boy via .NET 247 |
last post by:
(Type your message here)
Hi everyone,
I would like to ask a question about aligning text within one label.
I have an application that everytime the user click on Enter Record button, they will...
|
by: Arpan |
last post by:
Assume that a database table has the following 4 columns - ID, UserID,
Subject & Marks. I am retrieving the records existing in this DB table
& displaying them in a DataGrid like this:
<script...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |