wxWidget~How to GetSelectedRows()

hi everyone, im stuck in this froblem for long.....,
i use wxWidget, but cant find an information about how to use wxGrid functions
i fail to use GetSelectedRows(),GetSelectedCols(), IsInSelection() and etc
i wrote this code and compiled well
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#include "wx/wx.h" 
#include <wx/grid.h>
#include <wx/stattext.h>
#include <wx/textctrl.h>
#include <wx/dynarray.h>

WX_DEFINE_ARRAY_INT(int, ArrayInt);


class MyDialogDlgApp : public wxApp
    {
        public:
            bool OnInit();
            int OnExit();
    };
#define MyDialogDlg_STYLE wxCAPTION | wxSYSTEM_MENU | wxDIALOG_NO_PARENT | wxMINIMIZE_BOX | wxCLOSE_BOX

class MyDialogDlg : public wxDialog
    {
        private:
            DECLARE_EVENT_TABLE();
            wxGrid *WxGrid1;
			wxStaticText *T_Alamat;
			wxStaticText *T_Nama;
			wxTextCtrl *WxEdit2;
			wxTextCtrl *WxEdit1;  
            
        public:
        	MyDialogDlg(wxWindow *parent, wxWindowID id = 1, const wxString &title = wxT("mygrid1"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = MyDialogDlg_STYLE);
			virtual ~MyDialogDlg();
			void WxEdit1Enter(wxCommandEvent& event);
			void WxEdit2Enter(wxCommandEvent& event);
			void WxGrid1SelectCell(wxGridEvent& event);
            enum
			{
				////GUI Enum Control ID Start
				ID_WXGRID1 = 1005,
				ID_T_ALAMAT = 1004,
				ID_T_NAMA = 1003,
				ID_WXEDIT2 = 1002,
				ID_WXEDIT1 = 1001,
				////GUI Enum Control ID End
				ID_DUMMY_VALUE_ //don't remove this value unless you have other enum values
			};

        private:
			void OnClose(wxCloseEvent& event);
			void CreateGUIControls();
    }; 
//----------event table
BEGIN_EVENT_TABLE(MyDialogDlg,wxDialog)
	EVT_CLOSE(MyDialogDlg::OnClose)	
	EVT_GRID_SELECT_CELL(MyDialogDlg::WxGrid1SelectCell)
	EVT_TEXT_ENTER(ID_WXEDIT2,MyDialogDlg::WxEdit2Enter)
	EVT_TEXT_ENTER(ID_WXEDIT1,MyDialogDlg::WxEdit1Enter)
END_EVENT_TABLE()

//------------implement
IMPLEMENT_APP(MyDialogDlgApp)
bool MyDialogDlgApp::OnInit()
    {
        MyDialogDlg* dialog = new MyDialogDlg(NULL);
        SetTopWindow(dialog);
        dialog->Show(true);
        return true;
    } 

int MyDialogDlgApp::OnExit()
    {
        return 0;
    }
 

MyDialogDlg::MyDialogDlg(
						wxWindow *parent, 
						wxWindowID id, 
						const wxString &title, 
						const wxPoint &position, 
						const wxSize& size, 
						long style
						)
: wxDialog(parent, id, title, position, size, style)
{
	CreateGUIControls();
}

MyDialogDlg::~MyDialogDlg()
{
} 

 void MyDialogDlg::CreateGUIControls()
{
	//Do not add custom code between
	//GUI Items Creation Start and GUI Items Creation End.
	//wxDev-C++ designer will remove them.
	//Add the custom code before or after the blocks
	////GUI Items Creation Start

	WxGrid1 = new wxGrid(this, ID_WXGRID1, wxPoint(16, 83), wxSize(480, 289), wxRAISED_BORDER);
	WxGrid1->SetFont(wxFont(8, wxSWISS, wxNORMAL, wxNORMAL, false, wxT("Segoe UI")));
	WxGrid1->SetDefaultColSize(200);
	WxGrid1->SetDefaultRowSize(25);
	WxGrid1->SetRowLabelSize(20);
	WxGrid1->SetColLabelSize(25);
	WxGrid1->CreateGrid(12,2,wxGrid::wxGridSelectRows);

	T_Alamat = new wxStaticText(this, ID_T_ALAMAT, wxT("Alamat"), wxPoint(18, 49), wxDefaultSize, wxALIGN_LEFT, wxT("T_Alamat"));

	T_Nama = new wxStaticText(this, ID_T_NAMA, wxT("Nama"), wxPoint(17, 21), wxDefaultSize, wxALIGN_LEFT, wxT("T_Nama"));

	WxEdit2 = new wxTextCtrl(this, ID_WXEDIT2, wxT("WxEdit1"), wxPoint(90, 49), wxSize(188, 23), wxTE_PROCESS_ENTER, wxDefaultValidator, wxT("WxEdit2"));

	WxEdit1 = new wxTextCtrl(this, ID_WXEDIT1, wxT("WxEdit1"), wxPoint(91, 16), wxSize(188, 23), wxTE_PROCESS_ENTER, wxDefaultValidator, wxT("WxEdit1"));

	SetTitle(wxT("mygrid1"));
	SetIcon(wxNullIcon);
	SetSize(198,44,538,421);
	Center();
	
	////GUI Items Creation End
	WxEdit1->Clear();
	WxEdit2->Clear();
	WxEdit1->SetFocus();
}


	
void MyDialogDlg::OnClose(wxCloseEvent& /*event*/)
    {
		wxMessageBox("Tutup Aja yach");
        Destroy();
    }
    
void MyDialogDlg::WxEdit1Enter(wxCommandEvent& event)
    {
        WxEdit2->SetFocus();
    }

/*
 * WxEdit2Enter
 */
void MyDialogDlg::WxEdit2Enter(wxCommandEvent& event)
{
    static int row = WxGrid1->GetGridCursorRow();
    WxGrid1->SetCellValue(row,0,WxEdit1->GetLineText(1));
    WxGrid1->SetCellValue(row,1,WxEdit2->GetLineText(1));
    WxGrid1->SetGridCursor(row++,0);
    WxEdit1->Clear();
    WxEdit2->Clear();
    WxEdit1->SetFocus();
}

/*
 * WxGrid1SelectCell
 */
void MyDialogDlg::WxGrid1SelectCell(wxGridEvent& event)
{
    wxArrayInt myint;
    wxString mystring;
    myint = WxGrid1->GetSelectedRows();
    mystring<<myint.GetCount();
    //wxMessageBox(mystring); will show 0
	if(WxGrid1->IsInSelection(2,0))
	   {
            wxMessageBox("2.0 selected");
        }
        else
        {
            wxMessageBox("2.0 not selected");
        }
}

my froblem is in WxGrid1SelectCell function, myint.getcount() return 0, and IsInSelection return false; can anyone correct my code?
Topic archived. No new replies allowed.