Problem with Listbox.EditCell

I got a listbox1, where I chose one line. After cellclick I fill a form with the values out of the line, where I made cellclick.

Then I fill another Listbox2 with items out of database, which belong to the one item from cellclick (these items are not in the list)
Before I fill this second Listbox, I create an empty line in the listbox2.
After filling the Listbox2 there stands at the end of the method, which fills the list:

Listbox2.CellType(0,1) = Listbox.TypeEditableTextField Listbox2.EditCell(0, 1)

This works fine, the first time after the cellclick in Listbox1.
When I then created a new item in Listbox2, I immediately save it into the Database and fill again the Listbox2 with all items (after deleteallrows) with the same method as the first time.

The first time I am with the focus in the first row and second column of Listbox2 and can create a new item right away.
But after saving and refilling the list, I have to click there with the cursor. I do not have the focus in this field though it is the same routine.

Anybody an idea, why this doesn’t work the second time?

You wrote “The ListBox do not have the focus…"

so, after saving and refilling the list, set the window focus to the ListBox with

ListBox2.SetFocus

Check SetFocus.

The Listbox has got the focus, but not this cell 1st row second column, where I have to fill in a new item. It is blue (active) , but not as it stands in the reference:

[quote]ListBox.EditCell ( Row as Integer,Column as Integer )
Scrolls the Row, Column cell into view (if necessary) and temporarily makes the cell editable.
Row and Column are zero-based. It sets the focus within the ListBox to the Row, Column cell and selects its contents, if any. The editable cell has a focus ring around it. [/quote]

Return True from cellclick after calling editcell.

The editcell doesn’t work properly, when I call it in a routine, where I filled the whole list.

In this situation it isn’t possible, to insert “return true”

I’m sorry, I don’t quite follow. Where is the code called from? Your initial post indicated cellclick.

Listbox1 … List of items … Cellclick in one Line (ITEM X) -> Listbox2 is filled withe properties of Item X. Additionally an empty Line is produced on top of Listbox 2, so you can add another property. The ( 2nd column in Line 0) Field is made editable with editcell. This works!

After “enter” or “return” which includes the new property into the list in Listbox 2 (actually into the database -> deleteallrows in Listbox 2 and load all properties from database again) the complete first, empty line is in blue color and to get into the cell (2nd column) , where I want to add a new property, I have to click there with the mouse. But I would prefer to write one property after another and only type enter, to get to the next one (like in Excel).

And the code is called from Cellaction in the field, checking, if the key is chr(13) or chr(3)

I need to use Cellaction, wehre “return true” is not possible, because in KeyDown I do not get returned the row and column, which I need, because sometimes I want to edit a line beneath and not only add a new property in line 0.

So lets tell my problem the other way around:
I want to acquire new datas in the first line of a listbox (2nd column) and after having finished the input with enter, the data hase to be stored in database and I want to be in a new first, empty line and want to type in the next data, without having to click on this cell.

Furthermore I want to be able to edit items, when entering a field, where already data is standing.

[quote=211262:@Robert Blazek]So lets tell my problem the other way around:
I want to acquire new datas in the first line of a listbox (2nd column) and after having finished the input with enter, the data hase to be stored in database and I want to be in a new first, empty line and want to type in the next data, without having to click on this cell.

Furthermore I want to be able to edit items, when entering a field, where already data is standing.[/quote]

Is there anything wrong with http://documentation.xojo.com/index.php/ListBox.EditCell ?

It should work this way:

in the cellKeyDown event,
check the ascii value of the key to intercept Tab, Enter and Return

if asc(key) = 9 or asc(key) = 3 or asc(key) = 13 then
// Tab, enter or retrun, do your database stuff and add a new line and make the cell in column 1 editable
me.AddRow " "
me.CellType(me.ListCount-1,1) = Listbox.TypeEditableTextField
me.EditCell(me.ListCount-1, 1)
return true
else
// return false to simply accept the input
return false
end if

a little update to the previous code, to add a new row only if the editable cell is the LAST row of the listbox.
if the editable cell is in a row that has an existing following row, that row gets the focus and is made editable

if asc(key) = 9 or asc(key) = 3 or asc(key) = 13 then
me.AddRow " "
if row = me.listcount-1 then
me.CellType(me.ListCount-1,1) = Listbox.TypeEditableTextField
me.EditCell(me.ListCount-1, 1)
else
me.EditCell(row+1, 1)
end if
return true
else
return false
end if

[quote]Is there anything wrong with http://documentation.xojo.com/index.php/ListBox.EditCell ?[/quote] :

And exactly this doesn’t happen.

It doesn’t set the focus to Row and column, it sets the focus to the whole row. Therefore I have to select the column again to enter datas.

To GIulio
Thanks for your suggestion.
Actually this I have solved, but it does not work properly.
Here my code:

[code] dim sql as String
if row=0 and Titellist.cell(0,1)<>"" then // The list is already filled and the toprow is empty.
Titellist.cell(0,0)=str(Titellist.Listcount) // in Column 0 are numbers, which are also in the database
sql = “INSERT into Titel (InvNr,Nr,Name) Values (”+ InvNr.text + “, " + Titellist.cell(0,0) + “, '” + fuerDB(Titellist.cell(0,1)) +”’)"
elseif row<>0 then // edited Data
if Titellist.cell(Titellist.listindex,1)<>"" then
sql = “UPDATE Titel SET Name = '”+fuerDB(Titellist.cell(Titellist.listindex,1))+"’ WHERE InvNr = “+InvNr.Text+” AND Nr = "+ Titellist.cell(Titellist.listindex,0)
else // if cell is empty delete in Database
sql = "DELETE from Titel WHERE InvNr = “+InvNr.Text+” AND Nr = "+ Titellist.cell(Titellist.listindex,0)
end if
end if
Sammler.SQLexecute(sql)

If Sammler.Error Then
MsgBox Sammler.ErrorMessage
Sammler.rollback
else
Sammler.Commit
end if

titelfill // In this routine all rows in listbox are deleted and then the listbox is filled with the values from database
[/code]

[code] SUB titelfill

Titellist.DeleteAllRows

Titellist.Addrow("")
Titellist.cell(0,1)=""

DIM sql as String
dim rs as RecordSet
if Suchtext1.text="" then

sql = “SELECT * FROM Titel where InvNr= " + InvNr.text + " ORDER BY Nr DESC”
else
sql = “SELECT * FROM Titel where InvNr= " + InvNr.text + " AND Name Like '%”+fuerDB(Suchtext1.Text)+"%’ ORDER BY Nr DESC"
end if
rs=Sammler.sqlselect(sql)

If Sammler.Error Then
MsgBox Sammler.ErrorMessage
end if

While NOT rs.EOF
Titellist.Addrow(rs.field(“Nr”).Stringvalue)
Titellist.Cell(Titellist.lastindex,1)=vonDB(rs.field(“Name”).Stringvalue)
rs.MoveNext
Wend

Titellist.CellType(0,1) = Listbox.TypeEditable
titellist.EditCell(0, 1)

[/code]

For me the thing, which I do not understand:

This routine “titelfill” is also used in the first event, when I come to this point, when I cellclick in another Listbox, to show this listbox:

[code] DIM sql as String
Dim p as Picture
dim rs as RecordSet

sql = "SELECT Bild FROM Sammlung where InvNr= " + InvNr.text

rs=Sammler.sqlselect(sql)

If Sammler.Error Then
MsgBox Sammler.ErrorMessage
end if


if (rs.Field(“Bild”).stringvalue)<>"" then
Dim s As String = decodebase64(rs.Field(“Bild”).stringvalue)
Dim mb As MemoryBlock = s
Imagewell1.image= p.FromData(mb)
End if

Titelfill[/code]

In ListBox1.CellClick event I actually have:

[code] If EditMode Then
LB.CellType(row,column) = ListBox.TypeEditableTextField // or ListBox.Editable ?
LB.EditCell(row,column)

Else
LB.CellType(row,column) = ListBox.TypeNormal
End If[/code]

EditMode is for a MenuItem and is a Window Property.

Run the project and a simple click do what you ask.

Is it OK now ?

[quote=211280:@Robert Blazek]Is there anything wrong with http://documentation.xojo.com/index.php/ListBox.EditCell ?
:

“It sets the focus within the ListBox to the Row, Column cell and selects its contents, if any”
And exactly this doesn’t happen.

It doesn’t set the focus to Row and column, it sets the focus to the whole row. Therefore I have to select the column again to enter datas.[/quote]

Strange. Here, I can do that in a button and it does edit the content of 2,2 :

Listbox1.EditCell(2,2) ListBox1.

I did not even need the type editable thing.

To avoid having the whole row selected, I do :

Listbox1.EditCell(2,2) Listbox1.Selected(2) = False

Emile, I do not understand the sense of your posting.

I do not want to click into the cell! That is what I want to avoid!

(In excell you do not have to click to every cell, before you edit there, you can simply press enter and you are in the next cell)

Michel - it works also in my routines, but only the first time, when I come in. (cellclick from other listbox)

Robert: sorry, language barrier, eyes are loud (sleeping), age comes, etc.

Michel:
I had a lot of troubles trying to Edit a Cell of a ListBox until for unknow reasons, it started to works and works reliably (“do always the same job if I do the same clicks / keyboards actions”…)

Now it is slow when I drag a Row to the top or to the bottom…

At last, I’m goint to eat something and eventually do a nap !