Basic4ppc - Windows Mobile Development  

Go Back   Basic4ppc - Windows Mobile Development > Main Category > Code Samples & Tips
Home Register FAQ Members List 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 Thread Tools Display Modes
  #1 (permalink)  
Old 06-26-2008, 09:39 AM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 3,185
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.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: Combobox in editable table

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.1 KB, 46 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: 1,752
Awards Showcase
Beta Tester Forum Contributer 
Total Awards: 2
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: 3,185
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: 1,752
Awards Showcase
Beta Tester Forum Contributer 
Total Awards: 2
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: 3,185
Default

Thanks agraham.
I've fixed this bug and updated the source code.
This is the change:
Code:
Sub CalcColumnPosition (colNumber)
    x = editTable.x
    o.Value = obj.RunMethod3("HitTest",x,"System.Int32",editTable.y,"System.Int32")
    If o.GetProperty("Type") = "None" Then editTable.y = editTable.y - editTable.rowHeight
...
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: 130
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

Sony Ericsson XPERIA X1i WM6.1
480x800 Display Resolution
with QWERTY keyboard
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: 1,752
Awards Showcase
Beta Tester Forum Contributer 
Total Awards: 2
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:
txtEdit.SelectionLength = StrLength(txtEdit.Text)
oh.SetProperty("Enabled", false)
ov.SetProperty("Enabled", false)
txtEdit.Focus

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: 1,752
Awards Showcase
Beta Tester Forum Contributer 
Total Awards: 2
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(13) Then
 	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: 3,185
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: 130
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, 40 views)
__________________
Rioven

Sony Ericsson XPERIA X1i WM6.1
480x800 Display Resolution
with QWERTY keyboard

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



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 On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Editable table davelew1s Questions & Help Needed 6 06-18-2008 04:06 PM
Using rapi from desktop to copy file from device to desktop sunnyboyj Questions & Help Needed 9 02-08-2008 12:40 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 & Help Needed 2 05-13-2007 11:34 AM


All times are GMT. The time now is 04:00 AM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0