Поиск блогу

четверг, 30 июня 2011 г.

Получение данных выделенной строки из таблицы

Вывод выделенной строки оказался весьма нетривиальным заданием.

Данный фрагмент кода выведет в MessageBox содержимое выделенной строки в табличном контроле с названием "Журнал заявки".

LayoutHelper layoutHelper = new LayoutHelper(CardControl.LayoutControl, CardControl.BarManager, Session, CardData.Type.Id);
DocsVision.BackOffice.View.WinForms.LayoutItems.ICustomPropertyItem propertyItem = layoutHelper.GetCustomPropertyItem("Журнал заявки");
var refMapper = new CardPropertyDescriptionMapper(Session);
DocsVision.BackOffice.Model.CardProperties.Entities.CardPropertyTable cpt = null;
foreach (DocsVision.BackOffice.Model.Layouts.Entities.CardPropertyTableDescription refPropertyTableDesc in refMapper.FindTableProperties(CardData.Type.Id))
          {
              if (refPropertyTableDesc.Name == "Журнал заявки")
               {
                 var propertyMapper = new CardPropertyMapper(Session, CardData.Id, DomainObject.CustomPropertiesSectionId);
                   cpt = propertyMapper.FindTable(refPropertyTableDesc);
                   break;
               }
          }
System.Reflection.Assembly asm = System.Reflection.Assembly.Load("DocsVision.BackOffice.View, Version=4.5.0.0, Culture=neutral, PublicKeyToken=7148afe997f90519");
Type tableType = asm.GetType("DocsVision.BackOffice.View.WinForms.PropertyControls.TablePropertyControl");
var propInfo = tableType.GetProperty("GridView");
object ooo = propInfo.GetValue(propertyItem.Control, System.Reflection.BindingFlags.NonPublic, null, null, System.Globalization.CultureInfo.InvariantCulture);
DocsVision.BackOffice.View.WinForms.Controls.GridExView gridExView = ooo as DocsVision.BackOffice.View.WinForms.Controls.GridExView;
DevExpress.XtraGrid.Views.Grid.GridView gridView = gridExView as DevExpress.XtraGrid.Views.Grid.GridView;
object key = ((System.Data.DataRowView)gridView.GetFocusedRow()).Row[gridExView.KeyField];
          foreach (DocsVision.BackOffice.Model.CardProperties.Entities.CardPropertyTableRow row in cpt.Rows)
          {
              if (row.Key == (Guid)key)
              {
                  string message = "";                  
                  foreach (DocsVision.BackOffice.Model.CardProperties.Entities.CardProperty cellProp in row.Cells)
                      {
                       object val = cellProp.Value;                          
                       message += val == null ? "null" : val.ToString();
                       message += " ";    
                      }
                      MessageBox.Show(message);
                      }
    
              }


Для работы скрипта нужно прописать в using:

using DocsVision.Platform.WinForms.DataSource;
using DocsVision.BackOffice.Model.CardProperties.DataAccess;


Возможно, что-то еще...

а также подключить сборки DevExpress. А именно
DevExpress.XtraLayout.9.2.dll
DevExpress.XtraGrid.9.2.dll
DevExpress.Data.9.2.dll
DevExpress.Utils.9.2.dll

0 коммент.:

Отправить комментарий