Thanks Jerome,that's great!
After adding double-click event,noticed there is a sligth problem,when double click on the second row,the sort order of the both row changed.Don't know why.
Code: Select all
import "ecere"
import "ShortDate"
class Form1 : Window
{
text = "Form1";
background = activeBorder;
borderStyle = sizable;
hasMaximize = true;
hasMinimize = true;
hasClose = true;
size = { 640, 480 };
nativeDecorations = true;
DataField dfId
{
class(uint), width = 40,
header = "ID"
};
DataField dfName
{
class(String), width = 100,
header = "姓名", editable = true
};
DataField dfBirthday
{
class(ShortDate), width = 80,
header = "出生日期", editable = true
};
DataField dfHobbies
{
class(String), width = 200,
header = "喜好", editable = true
};
ListBox listBox1
{
this, size = { 500, 132 }, position = { 24, 24 }, moveRows = true, true, true, hasHeader = true, sortable = true;
bool NotifyDoubleClick(ListBox listBox, int x, int y, Modifiers mods)
{
char* name=listBox.currentRow.GetData(dfName);
int id=listBox.currentRow.GetData(dfId);
char IDstr[3];
char temp[20];
sprintf(IDstr,":ID=%d",id);
strcpy(temp,name);
strcat(temp,IDstr);
MessageBox{contents=temp}.Modal();
delete name;
return true;
}
};
Form1()
{
DataRow row;
listBox1.AddField(dfId);
listBox1.AddField(dfName);
listBox1.AddField(dfBirthday);
listBox1.AddField(dfHobbies);
row = listBox1.AddRow();
row.tag = 1;
row.SetData(dfId, 1);
row.SetData(dfName, "王小早");
row.SetData(dfBirthday, Date { 1987, june, 26 });
row.SetData(dfHobbies, "打球、下棋、听音乐");
row = listBox1.AddRow();
row.tag = 2;
row.SetData(dfId, 2);
row.SetData(dfName, "王小早 2");
row.SetData(dfBirthday, Date { 1988, june, 26 });
row.SetData(dfHobbies, "打球、下棋、听音乐");
}
}
Form1 form1 {};
And one more question,trying win32 API PlaySound in a new added button event caused the app failed to build.
Code: Select all
Compiling...
grid.ec
grid.ec:1:1: error: Couldn't open obj/debug.win32\grid.sym
grid (Debug) - 1 error, no warning
Last time I encountered the same issue when I tried win32 API ShellExecute,since it failed,I use ShellOpen in the eC SDK.Below is the full source code with the issue.Please also note I've added winmm(.a) in the linker and placed the sound file in the project folder.
Code: Select all
#ifdef __WIN32__
#define WIN32_LEAN_AND_MEAN
#include <windefs.h>
#include <windows.h>
#include <mmsystem.h>
#endif
import "ecere"
import "ShortDate"
class Form1 : Window
{
text = "Form1";
background = activeBorder;
borderStyle = sizable;
hasMaximize = true;
hasMinimize = true;
hasClose = true;
size = { 640, 480 };
nativeDecorations = true;
DataField dfId
{
class(uint), width = 40,
header = "ID"
};
DataField dfName
{
class(String), width = 100,
header = "姓名", editable = true
};
DataField dfBirthday
{
class(ShortDate), width = 80,
header = "出生日期", editable = true
};
DataField dfHobbies
{
class(String), width = 200,
header = "喜好", editable = true
};
Button button1
{
this, text = "button1", position = { 384, 192 };
bool NotifyClicked(Button button, int x, int y, Modifiers mods)
{
PlaySound("hellowin.wav", NULL, SND_FILENAME | SND_ASYNC);
return true;
}
};
ListBox listBox1
{
this, size = { 500, 132 }, position = { 24, 24 }, moveRows = true, true, true, hasHeader = true, sortable = true;
bool NotifyDoubleClick(ListBox listBox, int x, int y, Modifiers mods)
{
char* name=listBox.currentRow.GetData(dfName);
int id=listBox.currentRow.GetData(dfId);
char IDstr[3];
char temp[20];
sprintf(IDstr,":ID=%d",id);
strcpy(temp,name);
strcat(temp,IDstr);
MessageBox{contents=temp}.Modal();
delete name;
return true;
}
};
Form1()
{
DataRow row;
listBox1.AddField(dfId);
listBox1.AddField(dfName);
listBox1.AddField(dfBirthday);
listBox1.AddField(dfHobbies);
row = listBox1.AddRow();
row.tag = 1;
row.SetData(dfId, 1);
row.SetData(dfName, "王小早");
row.SetData(dfBirthday, Date { 1987, june, 26 });
row.SetData(dfHobbies, "打球、下棋、听音乐");
row = listBox1.AddRow();
row.tag = 2;
row.SetData(dfId, 2);
row.SetData(dfName, "王小早 2");
row.SetData(dfBirthday, Date { 1988, june, 26 });
row.SetData(dfHobbies, "打球、下棋、听音乐");
}
}
Form1 form1 {};