Default values in tableselect I have a custom module that, among other things, shows the user of a certain role. I want some of the users in this tableselect, do already be checked and I have and arry with these uids.

Now, how do I chedk default values in my list? See code below:

$companies = 'mail1@test.org,test2@test.org';
$uids = array();
$comp_mail = explode(',', $companies);
foreach ($comp_mail as $mail) {
    $uids[] = db_query("SELECT uid FROM {users} WHERE mail = '$mail'")-&gt;fetchField();
}

$form['msg']['accounts'] = array(
    '#type' =&gt; 'tableselect',
    '#header' =&gt; $header,
    '#options' =&gt; $options,
    '#default_value' =&gt; in_array($uids),
    '#empty' =&gt; 'no companies',
);
in_array() returns a boolean (and takes two arguments), whereas Drupal is expecting an array to be passed for the default value.

The default value array needs to be keyed by the same key used for the options array, so in this case uid. The value for each array element should be TRUE or FALSE, to mark the element as checked or unchecked respectively.

$uids[1] = TRUE;
$uids[2] = FALSE;
$uids[3] = TRUE;
// etc.

$form['msg']['accounts'] = array(
  '#type' =&gt; 'tableselect',
  '#header' =&gt; $header,
  '#options' =&gt; $options,
  '#default_value' =&gt; $uids,
  '#empty' =&gt; 'no companies',
); 


EDIT

I haven't tested the following, but since your $uids array contains only the array keys you want checked, and a positive number is automatically cast to a boolean TRUE in PHP, you might get away converting your array in one step:

$uids = drupal_map_assoc($uids);