create a gui with list box ?

I want to develop a GUI ,where two list boxes should be there and in the first Listbox am displaying some folder names,in the second listbox I want to display details of each folder from listbox1 ,on click of particular folder in listbox1 it shoud display the folder contents in the listbox2, I developed one listbox which displays folder names am unable to link it to the second listbox

5 Comments

please help me out
What have you done so far, any idea why it doesn't work? Paste your code here.
function varargout = lbox2(varargin) % LBOX2 Application M-file for lbox2.fig % LBOX2, by itself, creates a new LBOX2 or raises the existing % singleton*. % % H = LBOX2 returns the handle to a new LBOX2 or the handle to % the existing singleton*. % % LBOX2('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in LBOX2.M with the given input arguments. % % LBOX2('Property','Value',...) creates a new LBOX2 or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before lbox2_OpeningFunction gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to lbox2_OpeningFcn via varargin. % Last Modified by GUIDE v2.5 21-Nov-2012 12:44:54
% Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @lbox2_OpeningFcn, ... 'gui_OutputFcn', @lbox2_OutputFcn, ... 'gui_LayoutFcn', [], ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end
if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT
% --- Executes just before lbox2 is made visible. function lbox2_OpeningFcn(hObject, eventdata, handles, varargin)
% Choose default command line output for lbox2 handles.output = hObject;
% Update handles structure guidata(hObject, handles);
if nargin == 3, initial_dir = pwd; elseif nargin > 4 if strcmpi(varargin{1},'dir') if exist(varargin{2},'dir') initial_dir = varargin{2}; else errordlg('Input argument must be a valid directory','Input Argument Error!') return end else errordlg('Unrecognized input argument','Input Argument Error!'); return; end end
% Populate the listbox load_listbox(initial_dir,handles) % Return figure handle as first output argument
% UIWAIT makes lbox2 wait for user response (see UIRESUME) % uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line. function varargout = lbox2_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % Get default command line output from handles structure varargout{1} = handles.output;
% ------------------------------------------------------------ % Callback for list box - open .fig with guide, otherwise use open % ------------------------------------------------------------ function listbox1_Callback(hObject, eventdata, handles) % hObject handle to listbox1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns listbox1 contents as cell array % contents{get(hObject,'Value')} returns selected item from listbox1
get(handles.figure1,'SelectionType'); if strcmp(get(handles.figure1,'SelectionType'),'open') index_selected = get(handles.listbox1,'Value'); file_list = get(handles.listbox1,'String'); filename = file_list{index_selected}; if handles.is_dir(handles.sorted_index(index_selected)) cd (filename) load_listbox(pwd,handles) else [path,name,ext] = fileparts(filename); switch ext case '.fig' guide (filename) otherwise try
open(filename)
catch ex
errordlg(...
ex.getReport('basic'),'File Type Error','modal')
end
end
end
end
% ------------------------------------------------------------
% Read the current directory and sort the names
% ------------------------------------------------------------
function load_listbox(dir_path,handles) dir_path='D:\SES\Database\'; cd (dir_path) dir_struct = dir(dir_path); [sorted_names,sorted_index] = sortrows({dir_struct.name}'); handles.file_names = sorted_names; handles.is_dir = [dir_struct.isdir]; handles.sorted_index = sorted_index; guidata(handles.figure1,handles) set(handles.listbox1,'String',handles.file_names,'Value',1)
% set(handles.text1,'String',pwd)
% --- Executes during object creation, after setting all properties. function listbox1_CreateFcn(hObject, eventdata, handles) % hObject handle to listbox1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called
% Hint: listbox controls usually have a white background, change % 'usewhitebg' to 0 to use default. See ISPC and COMPUTER. usewhitebg = 1; if usewhitebg set(hObject,'BackgroundColor','white'); else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor')); end
% --- Executes during object creation, after setting all properties. function figure1_CreateFcn(hObject, eventdata, handles) % hObject handle to figure1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called
% Add the current directory to the path, as the pwd might change thru' the % gui. Remove the directory from the path when gui is closed % (See figure1_DeleteFcn) setappdata(hObject, 'StartPath', pwd); addpath(pwd);
% --- Executes during object deletion, before destroying properties. function figure1_DeleteFcn(hObject, eventdata, handles) % hObject handle to figure1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% Remove the directory added to the path in the figure1_CreateFcn. if isappdata(hObject, 'StartPath') rmpath(getappdata(hObject, 'StartPath')); end
% --- Executes during object creation, after setting all properties. function edit1_CreateFcn(hObject, eventdata, handles) % hObject handle to edit1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end
am unable to put the folder details from one listbox to the other listbox and,its opening oly for two steps when doubleclick in the listbox1
Jan
Jan on 21 Nov 2012
Edited: Jan on 21 Nov 2012
@Arun: It is not useful to post a pile of unformatted code. In opposite it makes reading this thread harder such that this reduces the chance to get a helpful answer. Therefore it is recommended to post a minimal code snippet only, which reproduces the mentioned problem.
The explanation "I am unable" does not allow for an efficient answer, because we have to guess too much what's actually happening when your program runs.

Sign in to comment.

 Accepted Answer

Jan
Jan on 21 Nov 2012

0 votes

Have you seen this excellent example: FEX: uipickfiles-uigetfile-on-steroids ?
I assume you find all required techniques there.

More Answers (0)

Categories

Find more on Graphics Object Properties in Help Center and File Exchange

Products

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!