Sign in to follow this  
Followers 0
4Eyes

Need ideas for a GUI that allows user to choose column layout

4 posts in this topic

Folks,

I'm not looking for code here, just some GUI layout ideas.

I have a database with 50+ data fields. I'd like to allow the user to not only choose which fields to include in a report (via csv file), but the column order. Yes, I could simply create the csv file and allow the user to move the columns around in Excel, but that's not what I want.

I've come up with a few ides but all are pretty ugly:

1) Have a checkbox for each field and an associated combo box for each where the user could select the column position

2) Similar to the above, but no combo. I could use a ListView and add a column for each field. The header would be labelled 1 to 50. The user could shuffle the headers to represent the column layout.

3) Similar to 1, but detect which checkbox was just checked and have 1 combo box that allows the user to choose the column. The column order would be display in a label near the checkbox.

Can you think of something nifty?

Thanks.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Seems like what's most common nowadays is to display side-by-side lists.

Available fields on the left, and selected fields on the right.

I was bored... so maybe something along these lines?

#Include <GuiListBox.au3>
Global $DB_FIELDS[9] = [8,"ID","NAME","DOB","SSN", "ADDRESS","CITY","STATE","ZIP"], $DB_LIST, $RPT_LIST
Global $Selected[9] = [0,0,0,0,0,0,0,0,0], $msg, $count, $row, $curlist, $label[9]

Example()
Exit

Func Example()
GUICreate("", 720, 400)
$DB_LIST = GUICtrlCreateList("", 40, 32, 180, 300, $LBS_NOTIFY)
$RPT_LIST = GUICtrlCreateList("", 300, 32, 180, 300, $LBS_NOTIFY)
GUISetFont(12, 600, 0 , "Webdings")
$L_R_BUTTON = GUICtrlCreateButton("4", 245, 160, 30, 25)
$U_BUTTON = GUICtrlCreateButton("5", 350, 330, 30, 25)
GUICtrlSetState(-1, $GUI_DISABLE)
$D_BUTTON = GUICtrlCreateButton("6", 400, 330, 30, 25)
GUICtrlSetState(-1, $GUI_DISABLE)
GUISetFont(8, 600)
For $x = 1 To $DB_FIELDS[0]
  GUICtrlCreateLabel($DB_FIELDS[$x], 560, 40 + $x * 25, 70)
  $label[$x] = GUICtrlCreateLabel($Selected[$x], 640, 40 + $x * 25, 30)
Next
$PRINT_BUTTON = GUICtrlCreateButton("PRINT", 305, 365, 175, 25)
GUISetState()

Update_Lists()

While 1
  $msg = GUIGetMsg()
  Switch $msg
   Case $DB_LIST
      _GUICtrlListBox_SetCurSel($RPT_LIST, -1)
      GUICtrlSetData($L_R_BUTTON, "4")
      GUICtrlSetState($U_BUTTON, $GUI_DISABLE)
      GUICtrlSetState($D_BUTTON, $GUI_DISABLE)
      $curlist = 0 ; DB
   Case $RPT_LIST
      _GUICtrlListBox_SetCurSel($DB_LIST, -1)
      GUICtrlSetData($L_R_BUTTON, "3")
      GUICtrlSetState($U_BUTTON, $GUI_ENABLE)
      GUICtrlSetState($D_BUTTON, $GUI_ENABLE)
      $curlist = 1 ; RPT
   Case $L_R_BUTTON
      If $curlist Then
         Left()
      Else
         Right()
      EndIf
      Update_Lists()
   Case $U_BUTTON
     Up()
   Case $D_BUTTON
     Down()
   Case $PRINT_BUTTON
     Print()
   Case -3
     Exit
  EndSwitch
WEnd
EndFunc

;===================================================================================================
Func Right()
$row = _GUICtrlListBox_GetCurSel($DB_LIST) + 1
$y = 0
For $z = 1 to $DB_FIELDS[0]
  If Not $Selected[$z] Then $y += 1
  If $y = $row Then
   $count += 1
   $Selected[$z] = $count
   ExitLoop
  EndIf
Next
EndFunc

Func Left()
$row = _GUICtrlListBox_GetCurSel($RPT_LIST) + 1
For $z = 1 to $DB_FIELDS[0]
  If $Selected[$z] = $row Then $Selected[$z] = 0
  If $Selected[$z] > $row Then $Selected[$z] -= 1
Next
$count -= 1
EndFunc

Func Up()
$row = _GUICtrlListBox_GetCurSel($RPT_LIST) + 1
If $row = 1 Then Return
For $z = 1 to $DB_FIELDS[0]
  If $Selected[$z] = $row Then $Selected[$z] = -1
Next
For $z = 1 to $DB_FIELDS[0]
  If $Selected[$z] = $row - 1 Then $Selected[$z] = $row
  If $Selected[$z] = -1 Then $Selected[$z] = $row - 1
Next
Update_Lists()
_GUICtrlListBox_SetCurSel($RPT_LIST, $row - 2)
EndFunc

Func Down()
$row = _GUICtrlListBox_GetCurSel($RPT_LIST) + 1
If $row = $count Then Return
For $z = 1 to $DB_FIELDS[0]
  If $Selected[$z] = $row Then $Selected[$z] = -1
Next
For $z = 1 to $DB_FIELDS[0]
  If $Selected[$z] = $row + 1  Then $Selected[$z] = $row
  If $Selected[$z] = -1 Then $Selected[$z] = $row + 1
Next
Update_Lists()
_GUICtrlListBox_SetCurSel($RPT_LIST, $row)
EndFunc

Func Print()
Local $string
For $x = 1 to $count
  For $y = 1 to $DB_FIELDS[0]
   If $Selected[$y] = $x Then
    $string &= $DB_FIELDS[$y] & ","
    ExitLoop
   EndIf
  Next
Next
MsgBox("",0," Report data: " & StringTrimRight($string, 1))
EndFunc

Func Update_Lists()
_GUICtrlListBox_ResetContent($DB_LIST)
$Count = 0
For $x = 1 to $DB_FIELDS[0]
  If $Selected[$x] Then
   $Count += 1
  Else
   _GUICtrlListBox_AddString($DB_LIST, $DB_FIELDS[$x])
  EndIf
Next
_GUICtrlListBox_ResetContent($RPT_LIST)
For $x = 1 to $Count
  For $y = 1 to $DB_FIELDS[0]
   If $Selected[$y] = $x Then _GUICtrlListBox_AddString($RPT_LIST, $DB_FIELDS[$y])
  Next
Next

For $x = 1 To $DB_FIELDS[0] ; unnecessary loop - just for display labels
   GUICtrlSetData($label[$x], $Selected[$x])
Next
EndFunc
Edited by Spiff59

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Spiff59,

Hey that's pretty cool. It allows adjustment of the order at selection time and afterward too.

I was going to use a much simpler partial solution of a checkbox for each field. It doesn't allow adjustment of the field order though. Maybe I'm getting lazier or losing interest in my project.

I've adjusted your code to suit my situation and it is a much better solution. Thanks for the suggestion and code example.

Edited by 4Eyes

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I did find a glitch in the routine. If you move a few fields to the right and then click the arrow key while no field is selected it botches things up a bit. Removing the $curlist variable and modifying one of the case clauses seems to fix it up.

Case $L_R_BUTTON
  If _GUICtrlListBox_GetCurSel($DB_LIST) > -1 Then Right()
  If _GUICtrlListBox_GetCurSel($RPT_LIST) > -1 Then Left()
  Update_Lists()
Edited by Spiff59

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0