473,394 Members | 1,812 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

DataGrid TableStyle Problem and ScrollBar Problem

I have an Expense Data Entry form which contains a DataGrid showing various
expense categories. There are three columns Description, Cash Exp, Credit
Exp, where Description column is readonly.

Users have to press a checkbox to specify whether they want to use DataGrid
to provide break-up or provide total value in textbox. Now when checkbox is
unchecked I am setting the Enabled property of DataGrid to False and vice
versa. The problem is when enabled property is set back to True, the
scrollbar disappears.

Secondly, I am using TableStyle in order to change the color of datagrid to
show whether it is enabled or disabled. The problem if I click a cell in
Description column and then set the checkbox to uncheck, it does not changes
the color of the clicked cell. It leaves the color same as the previous one.
This is happening only for Description column. I tried changing readonly
property of description column to false and it worked fine. It is just giving
an ugly look cos if I press more than one cell before un-checking it leaves
those cells as previous color and changes color for all others.

What could be going wrong? How can I fix it? Below is the code I am calling
on checkbox click event:

Private Sub EnableDataGrid(ByVal enabled As Boolean)

grdAExpenses.TableStyles.Clear()

Select Case enabled
Case True
grdAExpenses.BackgroundColor = Color.FromArgb(192, 255, 192)
Dim ts As New DataGridTableStyle
ts.MappingName = "ClientExpenses"
ts.AllowSorting = False
ts.RowHeadersVisible = False
ts.BackColor = Color.FromArgb(192, 255, 192)
ts.AlternatingBackColor = Color.FromArgb(192, 255, 192)

Dim cs As New DataGridTextBoxColumn
cs.MappingName = "Description"
cs.HeaderText = "Description"
cs.ReadOnly = True
cs.Width = 115
cs.TextBox.BackColor = Color.FromArgb(192, 255, 192)
ts.GridColumnStyles.Add(cs)

Dim noCol As New DataGridNumericTextBoxColumn
noCol.MappingName = "CashExpenditure"
noCol.HeaderText = "Cash Expenditure"
noCol.Format = "c"
noCol.Width = 100
noCol.Alignment = HorizontalAlignment.Right
noCol.TextBox.BackColor = Color.FromArgb(192, 255, 192)
ts.GridColumnStyles.Add(noCol)

noCol = New DataGridNumericTextBoxColumn
noCol.MappingName = "CreditExpenditure"
noCol.HeaderText = "Credit Expenditure"
noCol.Format = "c"
noCol.Width = 100
noCol.Alignment = HorizontalAlignment.Right
noCol.TextBox.BackColor = Color.FromArgb(192, 255, 192)
ts.GridColumnStyles.Add(noCol)

Me.grdAExpenses.TableStyles.Add(ts)
Me.grdAExpenses.Enabled = True

Case False
grdAExpenses.BackgroundColor = SystemColors.Control
Dim ts As New DataGridTableStyle
ts.MappingName = "ClientExpenses"
ts.AllowSorting = False
ts.RowHeadersVisible = False
ts.BackColor = SystemColors.Control
ts.AlternatingBackColor = SystemColors.Control

Dim cs As New DataGridTextBoxColumn
cs.MappingName = "Description"
cs.HeaderText = "Description"
cs.ReadOnly = True
cs.Width = 115
cs.TextBox.BackColor = SystemColors.Control
ts.GridColumnStyles.Add(cs)

Dim noCol As New DataGridNumericTextBoxColumn
noCol.MappingName = "CashExpenditure"
noCol.HeaderText = "Cash Expenditure"
noCol.Format = "c"
noCol.Width = 100
noCol.Alignment = HorizontalAlignment.Right
noCol.TextBox.BackColor = SystemColors.Control
ts.GridColumnStyles.Add(noCol)

noCol = New DataGridNumericTextBoxColumn
noCol.MappingName = "CreditExpenditure"
noCol.HeaderText = "Credit Expenditure"
noCol.Format = "c"
noCol.Width = 100
noCol.Alignment = HorizontalAlignment.Right
noCol.TextBox.BackColor = SystemColors.Control
ts.GridColumnStyles.Add(noCol)

Me.grdAExpenses.TableStyles.Add(ts)
Me.grdAExpenses.Enabled = False

End Select
End Sub
Jul 21 '05 #1
0 1533

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

Similar topics

2
by: Hajash | last post by:
hi all, how do i set the width of a column in a datagrid.Please help.Thanks in advance. regards, hajash
2
by: Josef Meile | last post by:
Hi, I'm using a ComboBox, some Textboxes, and a DataGrid to represent a many-to-many relationship between Person and Course. Each time that I change the value in the ComboBox (which for now is...
2
by: CSL | last post by:
I am using the DataGrid in a Windows Application, how can I adjust the widths of each column individually.
14
by: Brett Sinclair | last post by:
Hello everybody I'm still on the learning curve here...and from what I read, I created inherited datagrid class so I could have icons, combobox...etc in the columns of my datagrid. The grid...
6
by: Ron L | last post by:
I have a dataset whose source is a SQL 2k stored procedure that I am trying to display in a datagrid. This datasource has 4 columns that I am interested in here, a text column and 3 value columns...
2
by: Mac via DotNetMonster.com | last post by:
Hi all, I have a datagrid on a form which I have set the datasource (through the form designer) to be a dataset that I have added to the form, also through the form designer. I then have added a...
7
by: Earl | last post by:
Any known fixes for the wacky right-alignment bug in the WinForms datagrid (VS2003)? I've tried Ken's workaround...
0
by: Job Lot | last post by:
I have an Expense Data Entry form which contains a DataGrid showing various expense categories. There are three columns Description, Cash Exp, Credit Exp, where Description column is readonly. ...
4
by: Jeff | last post by:
I am stuck on trying to generate two columns headers for a datagrid on form load. I can use a datatable as the datasource and get the results I want, but I want to set different column widths and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.