Download the free trial version
Basic4android Video
Features
Tutorials and manuals
Showcase
Screenshots

Go Back   Android Development Forum - Basic4android > Basic4ppc (Windows Mobile) > Code Samples & Tips
Documentation Wiki Register Members List B4P Search Today's Posts Mark Forums Read

Code Samples & Tips Share your recent discoveries and ideas with other users.

Editable Table - Device & Desktop

Reply
 
LinkBack (1) Thread Tools Display Modes
  1 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 06-26-2008, 09:39 AM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 13,162
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default Editable Table - Device & Desktop

Using the attached code you can turn a regular table to an editable table.
The code uses the Door library to add a MouseDown event to the table control.
After calculating the cell upper left corner position, a panel with one textbox and one accept button is shown.



I hope you'll find this code useful.
It is more complex than it may seem because rows and columns could be partially or fully hidden.

Edit: V1.20 - The Editable table now supports AutoScale compilation. The updated code requires Door library v1.2 or newer: http://www.basic4ppc.com/forum/offic...ry-v1-2-a.html
Edit: V1.10 - Using the new modules feature all the editable code was moved to a separate module.
It is now possible to easily use more than one editable table in the same application.
Two new optional features:
- Validator - a sub that is called before changing any value and allows canceling the change if required.
- For each column you can choose whether to show a textbox or a combobox and choose the combobox values.
See this post for more details about using ComboBoxes: http://www.basic4ppc.com/forum/quest...html#post19103
Edit: V1.02 is attached. The edit panel will now disappear when one of the scrollbars is scrolled. The solution is based on agraham's code in post #7.
Edit: V1.01 is attached. It fixes the bug in post #4.
Attached Files
File Type: zip EditableTable.zip (4.5 KB, 215 views)
Reply With Quote
  #2 (permalink)  
Old 06-26-2008, 12:39 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 5,953
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

That's neat, I like that

However I can't work out why it needs a single pass through a timer Sub.

I tried disabling the timer and calling that Sub directly and it still seems to work the same, at least on the desktop. What subtlety am I missing that couldn't be achiieved with a suitably positioned DoEvents if a control refresh was required?
Reply With Quote
  #3 (permalink)  
Old 06-26-2008, 12:46 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 13,162
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

There are two subtle reasons why the timer is required.
MouseDown event occurs before SelectionChanged event.
At the end of SelectionChanged event the focus returns to the table.
So if we want to move the focus to the textbox we need to use the timer.
The second reason happens when you click on a partially hidden cell.
The table automatically scrolls the horizontal and/or vertical scrollbar in such way that the cell will be fully visible.
This rearrangement occurs after MouseMove event.
We must make the position calculations only after this rearrangement so again the timer is necessary.
Reply With Quote
  #4 (permalink)  
Old 06-26-2008, 01:49 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 5,953
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

Quote:
Originally Posted by Erel View Post
At the end of SelectionChanged event the focus returns to the table. So if we want to move the focus to the textbox we need to use the timer.
Thanks Erel, I hadn't noticed this - I see it now.
Quote:
This rearrangement occurs after MouseMove event.
This took me a while to see. However there seems to be a bug/feature in that clicking on a partially exposed row 11 (last row) actually positions the text box on row 12 (non-existent) rather than on top of the cell on row 11 and clicking on a partially exposed row 11 cell 3 offsets the editbox to the right as well, both somewhat spoiling the effect. Additional tests needed perhaps?
Reply With Quote
  #5 (permalink)  
Old 06-26-2008, 02:10 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 13,162
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

Thanks agraham.
I've fixed this bug and updated the source code.
This is the change:
Code:
Sub CalcColumnPosition (colNumber)
    x = editTable.x
    <b>o.Value = obj.RunMethod3(
"HitTest",x,"System.Int32",editTable.y,"System.Int32")
    
If o.GetProperty("Type") = "None" Then editTable.y = editTable.y - editTable.rowHeight
</b>...
Now we first check that the current position is a cell. If it is not a cell (which happens when we press on the last row and it's partially hidden) then y is updated to the previous row.
Reply With Quote
  #6 (permalink)  
Old 06-27-2008, 08:32 AM
Senior Member
 
Join Date: May 2007
Posts: 174
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Hi Erel,
How to catch the scroll bar properties on mousedown event on table?
I just want to disable the scroll bars during input so that the input panel will not be displaced from the selected cell when scroll bars are moved.
__________________
Rioven

DEVICE: Motorola ATRIX (Dual Core) Android 2.2.1
DESKTOP: Intel Pentium Dual-core E5200; Microsoft® Windows® Vista Home (Basic); Hard Disk:320GB; Memory:4096MB
Reply With Quote
  #7 (permalink)  
Old 06-27-2008, 09:46 AM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 5,953
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

Quote:
Originally Posted by Rioven View Post
How to catch the scroll bar properties on mousedown event on table?
This code will disable the Scrollbars from user control, however the table will still re-arrange itself if clicked on a partially hidden cell. oh and ov are Door library Objects.
Code:
oh.New1(false
ov.New1(
false
obj.FromControl(TableName)
o.Value = obj.GetProperty(
"Controls")
oh.Value = o.GetProperty2(
"Item",0' 0 = hscrollbar, 1 = vscrollbar
ov.Value = o.GetProperty2("Item",1' 0 = hscrollbar, 1 = vscrollbar
oh.SetProperty("Enabled"false)
ov.SetProperty(
"Enabled"false)
EDIT:- Oh - I now see why you want this. Leave most of the above code in App_Start and insert these two lines at the end of Timer1_Tick. The scrollbars seem to automatically re-enable after input.
Code:
<i>txtEdit.SelectionLength = StrLength(txtEdit.Text)</i>
<b>oh.SetProperty(
"Enabled"false)
ov.SetProperty(
"Enabled"false</b>)
<i>txtEdit.Focus</i>

Last edited by agraham : 06-27-2008 at 09:53 AM.
Reply With Quote
  #8 (permalink)  
Old 06-27-2008, 10:56 AM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 5,953
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

A further slight improvement might be to allow Return to end an edit. Add this Sub.
Code:
Sub txtEdit_KeyPress (key)
 
If key = Chr(13Then
     btnAccept_Click
 
End If
End Sub
Reply With Quote
  #9 (permalink)  
Old 06-27-2008, 02:05 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 13,162
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

V1.02 is attached to the first post.
Based on agraham's code it hides the edit panel when the user scrolls the scrollbars.
Reply With Quote
  #10 (permalink)  
Old 08-27-2008, 08:22 AM
Senior Member
 
Join Date: May 2007
Posts: 174
Awards Showcase
Beta Tester 
Total Awards: 1
Default Table Without the accept button 'X'

Hi Erel, Thanks very much for this very useful code. also thanks to agraham for other inputs.

Alternative updating table cell content which is... just leaving the cell.
This is more of my preference or maybe to some others.

I've made slight modifications which get rid of the accept button.
I've tested on device and found it works. maybe need to test with other devices.

here are what I did...
I have deleted the 'btnAccept' button and made some minor panel and textbox size adjustments...

then added ...

Sub txtEdit_lostFocus
btnAccept_click
End Sub

and also added 'btnAccept_click' on scroll bars

I hope I did it correctly...Please let me know

Regards,
Rioven


EDIT: updated file... see next post...
Attached Files
File Type: sbp EditableTable2.sbp (5.1 KB, 176 views)
__________________
Rioven

DEVICE: Motorola ATRIX (Dual Core) Android 2.2.1
DESKTOP: Intel Pentium Dual-core E5200; Microsoft® Windows® Vista Home (Basic); Hard Disk:320GB; Memory:4096MB

Last edited by Rioven : 09-03-2008 at 08:29 AM.
Reply With Quote
Reply



LinkBacks (?)
LinkBack to this Thread: http://www.basic4ppc.com/forum/code-samples-tips/2609-editable-table-device-desktop.html
Posted By For Type Date
Pocketinfo Dev-Challenge: Opdracht 3: Omrekenkoersen | Pocketinfo.nl » Blog This thread Refback 12-11-2008 09:42 PM
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Using rapi from desktop to copy file from device to desktop sunnyboyj Questions (Windows Mobile) 19 10-27-2010 02:08 PM
Editable table davelew1s Questions (Windows Mobile) 6 06-18-2008 04:06 PM
XYCalc -graphs an equation or editable table of figures in regular, bar or pie chart HarleyM Code Samples & Tips 2 11-24-2007 08:21 AM
Editable Table RandomCoder Code Samples & Tips 3 06-29-2007 11:17 PM
editable table ? giannimaione Questions (Windows Mobile) 2 05-13-2007 11:34 AM


All times are GMT. The time now is 03:22 AM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0