T
T
tolanych2017-04-12 10:28:41
SQL
tolanych, 2017-04-12 10:28:41

How to correctly implement validation when binding two text-boxes?

In C# (Windows Form)
I made the binding of the text field of the 1st User-Control to another as follows. They now completely reproduce each other.

this.controlFIO.FIO_T_FA.DataBindings.Add( "Text", this.controlFIO_M.FIO_T_FA, "Text", true, DataSourceUpdateMode.OnValidation );

How can I add an additional condition before the binding so that the value is picked up only if the text-box is empty?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
A
Alexander null, 2018-04-03
@snikes

You make a selection of all tables, and you already build the code as you like

A
alexalexes, 2018-04-03
@alexalexes

This can only be solved in a procedural programming context when post-processing query results, for example, in PHP.

/*Функция преобразования выборки в матрицу */
function get_matrix($rows)
{
  // получаем все значения по id - измерению матрицы (строки матрицы)
 // можно сделать запросом select distinct id from table order by id
  foreach($rows as $row)
    $id_dem[$row['id']] = 1;

 // получаем все значения по date - измерению матрицы (столбцы матрицы)
 // можно сделать запросом select distinct date from table order by date
  foreach($rows as $row)
    $date_dem[$row['date']] = 1;

$map = null;   // если нет значений размерности матрицы, то функция вернет null

// получаем карту не-null значений - непустые ячейки матрицы
  foreach($rows as $row)
    $map[$row['id']][$row['date']] = $row['count'];

// дополняем карту null значениями - получаем полноценную матрицу
  if(isset($id_dem) && isset($date_dem))
    foreach($id_dem as $id => $val_id)
      foreach($date_dem as $date => $val_date)
        $map[$id][$date] = array_key_exists($id, $map) && array_key_exists($date, $map[$id])
                             ? $map[$id][$date] : null;
   return $map;
}

C
Chronic 86, 2018-04-03
@chronic86

It's clear. So it's just post-processing. I hoped that there are mechanisms for implementing this in SQL.

S
Sergey, 2018-04-04
@viras777

And if there is one more record with id=1 in the selection?
You cannot change the number of columns in a query.
You can do it differently, the first column is id, the second is an array of count and the third is the date. This can be achieved using the array_agg
function

D
d-stream, 2017-04-12
@d-stream

Make checks on getters/setters.
Something like this

private string _mytext;
public string MyText {
get{return _mytext;} 
set { if (_mytext != "") {_mytext=value; OnPropertyChanged....}}

and bind MyText

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question