473,405 Members | 2,349 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,405 software developers and data experts.

increment a column's value in a datagrid

I derived my own custom class from the datagrid class.

I overrode the ProcessCmdKey Function, like this, to catch the up and down
arrow keys:

======

Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal
keyData As Keys) As Boolean
Const WM_KEYDOWN As Integer = &H100
Const WM_SYSKEYDOWN As Integer = &H104

If ((msg.Msg = WM_KEYDOWN) Or (msg.Msg = WM_SYSKEYDOWN)) Then
Select Case (keyData)
Case Keys.Down
RaiseEvent key_down()
Return True
Case Keys.Up
RaiseEvent key_up()
Return True
End Select
End If

Return MyBase.ProcessCmdKey(msg, keyData)
End Function

======

I added these events:

======

Public Event key_down()

Public Event key_up()

======

In a form, I added my custom datagrid, and I added these subs to my form to
handle those events:

(ReportedTime is a datatable).

======

Private Sub DataGrid1_key_down() Handles Datagrid1.key_down
If Not ReportedTime.Rows.Count = 0 Then
If Datagrid1.CurrentCell.ColumnNumber = 1 Then
If
ReportedTime.Rows(Datagrid1.CurrentCell.RowNumber) .Item(4) >= 1 Then
ReportedTime.Rows(Datagrid1.CurrentCell.RowNumber) .Item(4)
= ReportedTime.Rows(Datagrid1.CurrentCell.RowNumber) .Item(4) - 1
End If
ElseIf Datagrid1.CurrentCell.ColumnNumber = 2 Then
If
ReportedTime.Rows(Datagrid1.CurrentCell.RowNumber) .Item(5) >= 1 Then
ReportedTime.Rows(Datagrid1.CurrentCell.RowNumber) .Item(5)
= ReportedTime.Rows(Datagrid1.CurrentCell.RowNumber) .Item(5) - 1
End If
End If

Datagrid1.DataSource = ReportedTime
End If
End Sub

Private Sub DataGrid1_key_up() Handles Datagrid1.key_up

If Not ReportedTime.Rows.Count = 0 Then
If Datagrid1.CurrentCell.ColumnNumber = 1 Then
If
ReportedTime.Rows(Datagrid1.CurrentCell.RowNumber) .Item(4) <= 9 Then
ReportedTime.Rows(Datagrid1.CurrentCell.RowNumber) .Item(4)
= ReportedTime.Rows(Datagrid1.CurrentCell.RowNumber) .Item(4) + 1
End If
ElseIf Datagrid1.CurrentCell.ColumnNumber = 2 Then
If
ReportedTime.Rows(Datagrid1.CurrentCell.RowNumber) .Item(5) <= 58 Then
ReportedTime.Rows(Datagrid1.CurrentCell.RowNumber) .Item(5)
= ReportedTime.Rows(Datagrid1.CurrentCell.RowNumber) .Item(5) + 1
End If
End If

Datagrid1.DataSource = ReportedTime
End If
End Sub

======

However, the following problems have arisen:

1) If the datagrid is empty and I insert a numeric value into a cell, the
code within the two functions above is not evaluated since that datatable
has no rows yet. So, this basically makes the arrow keys worthless unless
the datagrid is already filled. Is there a way to change the cell's value
without having to access the datatable?

2) If there are two or more rows already in the datatable and displayed in
the datagrid, everything works great. The column increments via the up/down
arrow keys perfectly. However, if there is only one row in the datatable
(and of course, only one row displayed in the datagrid), it does not
increment, or at least not visually. The column only updates itself after I
click away from the active cell. So, I can increment it up or down all I
want, but I won't be able to know what the actual value I just created is
until I click away. The interesting thing about this single-row situation
is that if I click the asterisk in the datagrid (to create a new row), and
then click *back* to the original row (the new row disappears as normal),
the columns increment normally, and I can see how them do so in real time.

Any suggestions?

Thanks!

Matt
Jan 20 '06 #1
0 1904

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

Similar topics

2
by: Ryan P. Kennedy | last post by:
Reset the Identity Increment Hello: I have a table with a bigint type column (field) that has an identity seed of 1 and an identity increment of 1. The column is the primary key for the...
8
by: Bruce Stockwell | last post by:
the setup: Webservice/WinClient application/SQL server. VS.Net (visual basic) winform wizard creates a simple form with load cancel cancelall and datagrid bound to a simple Dataset with one...
11
by: Randell D. | last post by:
Folks, I have a table of addresses and a seperate table with contact names - All addresses tie to one or more names - I would like to keep track of the number of names 'belonging' to an address...
2
by: Targa | last post by:
I have a form field which displays a time in the format 5:30 PM - this time is selected from a previous page. I need to add a function to increment or deincrement the time by clicking up/down...
1
by: Dmitry V. Markin | last post by:
Good day! Here is my problem: I need to have a radiobutton column in my DataGrid for a representation of a bool column, where only row can be checked at one time(only one value in bool column...
0
by: Amber | last post by:
There are times when you will need to highlight or otherwise modify the contents of a particular DataGrid row-column value based upon the value in the column. In this example we will select the...
1
by: sianan | last post by:
I tried to use the following example, to add a checkbox column to a DataGrid in an ASP.NET application: http://www.codeproject.com/aspnet/datagridcheckbox.asp For some reason, I simply CAN'T get...
6
by: Agnes | last post by:
I understand it is impossible, but still curious to know "Can I freeze several column in the datagrid, the user can only scroll the first 3 columns (not verical), for the rest of the coulumn, it is...
10
by: JohnR | last post by:
I have a datatable as the datasource to a datagrid. The datagrid has a datagridtablestyle defined. I use the datagridtablestyle to change the order of the columns (so they can be different than...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
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...

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.