日期:2009-11-07  浏览次数:20453 次

    四. 实例介绍CheckBoxList组件的使用方法:
  
    (1).如何判定选择了组件中的哪些检查框:

  
    在程序中,是通过处理Selected属性和Count属性来完成的,具体如下:
  
  for ( int i = 0 ; i < ChkList . Items . Count ; i++ )
  {
  if( ChkList . Items [ i ] . Selected )
  {
  lblResult . Text += ChkList . Items [ i ] .Text + " <br > " ;
  }
  }
  
    (2).如何设定CheckBoxList组件的外观布局:
  
    CheckBoxList组件有比较多的属性来设定它的外观,在本文介绍的程序中,主要是通过四个方面来设定组件的外观布局的:组件中的检查框中的文本和选框的排列位置、组件中各个检查框布局、组件中各个检查框排列方向和组件中各个检查框的排列行数,具体的程序代码如下:
  
  //组件中的检查框中的文本和选框的排列位置
  switch ( cboAlign . SelectedIndex )
  {
   case 0 :
    ChkList . TextAlign = TextAlign . Left ;
    break ;
   case 1 :
    ChkList . TextAlign = TextAlign . Right ;
    break ;
  }
  //组件中各个检查框布局
  switch ( cboRepeatLayout . SelectedIndex )
  {
   case 0 :
    ChkList . RepeatLayout = RepeatLayout . Table ;
    break ;
   case 1 :
    ChkList . RepeatLayout = RepeatLayout . Flow ;
    break ;
  }
  
  //组件中各个检查框排列方向
  switch ( cboRepeatDirection . SelectedIndex)
  {
   case 0 :
    ChkList . RepeatDirection = RepeatDirection . Vertical ;
    break ;
   case 1 :
    ChkList . RepeatDirection = RepeatDirection . Horizontal ;
    break ;
  }
  
  //组件中各个检查框的排列行数
  try
  {
   int cols = int . Parse ( txtRepeatCols.Text ) ;
   ChkList . RepeatColumns = cols ;
  }
  catch ( Exception )
  {
  }