ComponentOne의 DataTree Grid를 사용하고 있습니다. 현재 DataTree 그리드에는 2 개의 레벨이 있습니다 (Parent & Child). 각 그리드의 각 행에는 사용자가 행을 선택할 수있는 체크 박스 열이 있습니다. 사용자가 부모 행을 선택하면 이벤트가 발생하고 flexgrid_CellChecked가 발생합니다. 자식 그리드가 선택되면, 발동 된 이벤트는 flexgrid_ChildCellChecked입니다. DataTree에 3 단계를 추가하고 가장 안쪽에있는 체크 상자가 선택되면 해당 이벤트가 발생하도록합니다. flexgrid_ChildChildCellChecked라고 부르 자.C#의 그리드에서 서로 다른 레벨의 다른 이벤트 핸들러 만들기
이 이벤트는 DataTree 클래스의 Expand (int 행) 메서드에서 인스턴스화됩니다. 문제는 첫 번째 자식 (레벨 2)이 확장되고 이벤트 ChildCellChecked 및 ChildChildCellChecked가 핸들러로 추가 될 수있는 경우입니다. 두 x 째 하위 (레벨 3)가 확장되면이 두 이벤트는 모두 널입니다. 내가 3 레벨 그리드의 두 번째 수준의 그리드 및 ChildChildCellChecked의 이벤트, ChildCellChecked를 만들 싶습니다
public class C1FlexDataTree : C1FlexGrid, ISupportInitialize
{
//--------------------------------------------------------------------------------
#region ** fields
// reference to hidden column that contains details rows for each master record
//
// this is created automatically by a DataSet based on its Relations.
//
// e.g. if the parent table is 'Orders', this could be an 'OrderDetails' table
// with the order details for each order on the master data table.
//
private Column _colChild = null;
// child grid that displays the headers rows over the native header rows.
//
// this grid appears on top of all child controls and prevents children from
// hiding the parent grid's header rows when they scroll.
//
private GridHeader _hdr = null; // <<1.1>>
// fire event to allow setting up child grids
// the event sender is the child grid that was just bound
public event EventHandler SetupColumns;
public event RowColEventHandler ChildCellChecked;
public event RowColEventHandler ChildChildCellChecked;
protected virtual void OnSetupColumns(object sender)
{
if (SetupColumns != null)
SetupColumns(sender, EventArgs.Empty);
}
protected virtual void OnChildCellChecked(object sender, RowColEventArgs e)
{
if (ChildCellChecked != null)
{
ChildCellChecked(sender, e);
}
}
protected virtual void OnChildChildCellChecked(object sender, RowColEventArgs e)
{
if (ChildChildCellChecked != null)
{
ChildChildCellChecked(sender, e);
}
}
// get top-level grid (overall parent)
public C1FlexDataTree ParentGrid
{
get
{
C1FlexDataTree parent = this;
while (parent.Parent is C1FlexDataTree)
parent = parent.Parent as C1FlexDataTree;
return parent;
}
}
// expand row
public bool ExpandRow(int row)
{
// sanity
if (row < Rows.Fixed || row >= Rows.Count)
{
return false;
}
// check that the row is not already expanded
C1FlexDataTree childGrid = Rows[row].UserData as C1FlexDataTree;
if (childGrid != null)
{
return false;
}
// check that we have a data source for this row
object dataSource = _colChild != null? _colChild[row] : null;
if (!(dataSource is IBindingList))
{
return false;
}
// ** fire before collapse event
var e = new RowColEventArgs(row, -1);
OnBeforeCollapse(e);
if (e.Cancel)
{
return false;
}
// add node row (unbound) to display child
Rows.InsertNode(row + 1, -1);
// make new row non-editable (it's just a placeholder)
Rows[row + 1].AllowEditing = false;
// create child grid
childGrid = new C1FlexDataTree();
childGrid.Visible = false;
childGrid.ScrollBars = ScrollBars.Horizontal;
// hook up event handlers
//When there is only 2 levels this 'if' statement is not needed.
//But with 3 levels, the ChildCellChecked is null
if (ChildCellChecked != null)
{
childGrid.CellChecked += new RowColEventHandler(ChildCellChecked);
}
// attach child grid to parent, set data source
Controls.Add(childGrid);
childGrid.DataSource = dataSource;
// save references:
// child grid Tag property contains a reference to the parent row
// parent row UserData contains a reference to the child grid
childGrid.Tag = Rows[row];
Rows[row].UserData = childGrid;
// make child grid visible, move it into position
childGrid.Visible = true;
childGrid.UpdatePosition();
childGrid.Focus();
//When _colChild is null, the 3rd level is being expanded.
//ChildChildCellChecked is null
if (childGrid._colChild == null)
{
childGrid.CellChecked += new RowColEventHandler(ChildChildCellChecked);
}
OnAfterCollapse(e);
// done
return true;
}
:
이
은 확장 방법과 DataTree 클래스입니다.그리드가 올바르게 표시되고 확장 및 축소 할 수 있습니다. 그러나 3 단계 그리드의 확인란을 클릭하면 이벤트가 실행되지 않습니다.
각 수준 그리드에 이벤트 처리기를 연결하려면 어떻게합니까?
UPDATE
수준이 2 인 경우, 확장되고있는 수준 식별하는 코드 조각 중 하나를 사용하여이 이벤트 ChildChildCellChecked은 null입니다.
첫 번째 레벨 호출 중에 Expand() 메소드가 호출되고 두 번째 레벨 호출 중에 디버그 모드에서 스크린 샷을 표시하는 문서를 첨부했습니다.
Expand()의 첫 번째 수준 호출 중에 ChildCellChecked가 만들어집니다.
두 번째 수준의 Expand() 호출 중에 ChildChildCellChecked가 null입니다. 예외가 발생합니다.
두 번째 수준에서 Expand()를 호출하는 동안 대리자 ChildChildCellChecked가 null 인 이유를 알 수 없습니다.
첨부 된 스크린 샷은 오류를 더 잘 나타낼 수 있습니다 ... 디버그 모드 중 2 번 촬영.
첫 번째 그립은 확장됩니다. 부모 모눈이 첫 번째 자식으로 확장 된 경우입니다. BOTH 이벤트가 정의 된 것을 볼 수 있습니다. ChildCellCheck 만 작성되었습니다.
두 번째 그리드가 확장되었습니다.
사실 모두 위임()를 확장하는 제 통화 중 각 이벤트의 방법과 연관되어 첫번째 아이 그리드 제 2 레벨 그리드를 표시하도록 확장 될 때, 이는 에러이다. Expand() 두 번째 호출 중에 대리자가 모두 null입니다.
자식 그리드가 만들어 질 때 수준에 관계없이 그 자식 그리드에 이벤트 처리기가 만들어 질 것이라고 생각했습니다.두 번째 수준의 눈금에 두 번째 이벤트 처리기가 필요하지 않습니다. 확인란을 클릭하면 이벤트가 실행되고 이벤트 메서드 내에서 어떤 자식 그리드 수준에서 이벤트가 발생했는지 확인할 수 있습니다.
글로리아 내가 원래 게시물에 게시 한 것처럼
원래 질문에 대한 업데이트를 추가했습니다 ... –