473,804 Members | 3,305 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

aligning datagrid columns

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.Te xt <> "*" Then
If txtEndDate.Text = "*" Then Exit Sub
End If
dvMain = GetDailySales(t xtUnitID.Text, txtStartDate.Te xt, 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.Ch ecked = 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)("Busi ness_Date")
DR(Col2) = BD.ToShortDateS tring
DR(Col3) = dvMain(X)("Stat us")
If IsDBNull(dvMain (X)("User_ID")) Then
DR(Col50) = dvMain(X)("User _ID")
Else
Update_User = dvMain(X)("User _ID")
DR(Col50) = Update_User.Sub string(12)
End If
DR(Col4) = Format(dvMain(X )("Deposit_Eve_ Amt"), "N")
If chkViewVerif.Ch ecked = True Then DR(Col55) =
dvMain(X)("Depo sit_Eve_Amt_Ver ified")
'--- assigning the rest of the values here
dtMain.Rows.Add (DR)
Next

dgDSR.DataSourc e = dtMain
dgDSR.DataBind( )

'---trying to align a column here (and it doesn't work)
dgDSR.Columns(2 ).ItemStyle.Hor izontalAlign = HorizontalAlign .Center

End Sub

Nov 18 '05 #1
1 1319
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.W ebControls.Data GridItem
tablerowitem = dgDSR.Controls( 0).Controls(0)
For Each tablerowitem In dgDSR.Items
tablerowitem.Ce lls(3).Horizont alAlign = HorizontalAlign .Center
If chkViewVerif.Ch ecked = True Then
tablerowitem.Ce lls(5).Horizont alAlign = HorizontalAlign .Center
tablerowitem.Ce lls(7).Horizont alAlign = HorizontalAlign .Center
tablerowitem.Ce lls(9).Horizont alAlign = HorizontalAlign .Center
tablerowitem.Ce lls(11).Horizon talAlign = HorizontalAlign .Center
tablerowitem.Ce lls(14).Horizon talAlign = HorizontalAlign .Center
tablerowitem.Ce lls(16).Horizon talAlign = HorizontalAlign .Center
tablerowitem.Ce lls(18).Horizon talAlign = HorizontalAlign .Center
tablerowitem.Ce lls(20).Horizon talAlign = HorizontalAlign .Center
tablerowitem.Ce lls(22).Horizon talAlign = 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.Te xt <> "*" Then
If txtEndDate.Text = "*" Then Exit Sub
End If
dvMain = GetDailySales(t xtUnitID.Text, txtStartDate.Te xt, 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.Ch ecked = 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)("Busi ness_Date")
DR(Col2) = BD.ToShortDateS tring
DR(Col3) = dvMain(X)("Stat us")
If IsDBNull(dvMain (X)("User_ID")) Then
DR(Col50) = dvMain(X)("User _ID")
Else
Update_User = dvMain(X)("User _ID")
DR(Col50) = Update_User.Sub string(12)
End If
DR(Col4) = Format(dvMain(X )("Deposit_Eve_ Amt"), "N")
If chkViewVerif.Ch ecked = True Then DR(Col55) =
dvMain(X)("Depo sit_Eve_Amt_Ver ified")
'--- assigning the rest of the values here
dtMain.Rows.Add (DR)
Next

dgDSR.DataSourc e = dtMain
dgDSR.DataBind( )

'---trying to align a column here (and it doesn't work)
dgDSR.Columns(2 ).ItemStyle.Hor izontalAlign = HorizontalAlign .Center

End Sub

Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3160
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 does). Problem is, it also right aligns the Column Header/Description in the process. The client is asking me to prevent this from happening. Is it possible to right align the data, but left align it's column headers? If so, how?
1
840
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 controlling the visibility of columns in the DataGrid control. The problem usually comes down to one fact. The DataGrid has a property called AutoGenerateColumns. The default value is "True". This means that when AutoGenerateColumns is set to True,...
2
2765
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 number of textboxes, but when there is only one textbox I need to be able to anchor it to the top of the column, at present it centers itself in the middle. Does anyone have any idea how to accomplish this?
3
4889
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 the best method? Do you have a sample of how to do this?
4
3499
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 snippet from my .css file: *************************** body { margin:0; padding:0;
2
6416
by: CSL | last post by:
I am using the DataGrid in a Windows Application, how can I adjust the widths of each column individually.
1
4004
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 DataColumn("Value", GetType(String))) For i = 0 To j - 1 dr = dt.NewRow()
1
1926
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 be prompt an input box to enter employee names and sales figures. The output then will be displyed in only 1 label using a For loop. The layout would be under 3 columns: Employee name (left justified), Sale figures (right justified) and Bonus...
7
3580
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 runat="server"> Sub Page_Load(obj As Object, ea As EventArgs) Dim dSet As DataSet Dim sqlConn As SqlConnection Dim sqlDapter As SqlDataAdapter
0
9708
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10588
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10340
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9161
agi2029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7623
isladogs
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6857
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5662
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4302
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3827
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.