Code Snippet05-ListBox(Multi Columns,various data types)

General help with the Ecere Cross Platform GUI toolkit: Window, common controls, events, etc.
Help with the 2D Graphics library: Surface, Display, Bitmap, Font and others.
Post Reply
samsam598
Posts: 212
Joined: Thu Apr 14, 2011 9:44 pm

Code Snippet05-ListBox(Multi Columns,various data types)

Post by samsam598 »

Purpose:Multiple column listbox acts as a grid or ListView control in other OOP GUI.Double click in a selected row will show related informatioin on the statusbar.

Code: Select all

 
import "ecere"
import "ShortDate" 
class Form1 : Window
{
   text = "Form1";
   background = activeBorder;
   borderStyle = sizable;
   hasMaximize = true;
   hasMinimize = true;
   hasClose = true;
   hasStatusBar = true;
   size = { 640, 480 };
   anchor = { horz = -3, vert = -5 };
   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, foreground = darkCyan, font = { "Tahoma", 10 }, anchor = { left = 0, top = 0, right = 0, bottom = 0 }, moveRows = 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[100];
         char temp[200];
         sprintf(IDstr,":ID=%d",id);
         strcpy(temp,name);
         strcat(temp,IDstr);
 
         //show name and ID you've selected in the statusBar:
         statusBar.text=temp;
 
         return false;
      }
   };
 
   Form1()   
   {
         FillListBox();   
   }
   void FillListBox()
   {
       DataRow row;
       int i;
       char name[100];  
       char hobbies[200];  
       listBox1.AddField(dfId);      
       listBox1.AddField(dfName);      
       listBox1.AddField(dfBirthday);      
       listBox1.AddField(dfHobbies);   
       for(i=0;i<50;i++)
       {
          sprintf(name,"王小早(%d)",i+1); 
          sprintf(hobbies,"打球、下棋、听音乐 (%d)",i+1);  
          row = listBox1.AddRow();      
          row.tag = i+1;      
          row.SetData(dfId, i+1);      
          row.SetData(dfName,name);      
          row.SetData(dfBirthday, Date { 1960+i, june, 26 });      
          row.SetData(dfHobbies, hobbies);       
 
       }  
   }
} 
Form1 form1 {};                                    
 
Post Reply