Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
145
Inserting a line is not reflected in UltraWinGrid
posted

Hi 

I have a ultrawingrid which does the sort externally. I should insert / delete a line in my grid at any time. This Insert / Delete works fine if the grid is not sorted. Otherwise the index is totally different compare to the source datatable. 

my code is as following:

"dgItems" is the name of the grid

void InsertNewLine()
{
try
{
int nNoOfRows = m_dtGridDataTable->Rows->Count;
int nCurrRowInd = -1;

nCurrRowInd = dgItems->ActiveRow->Index;

DataRow^ dr = m_dtGridDataTable->NewRow();
if(nCurrRowInd > 0)
dr["LineType"] = dgItems->Rows[nCurrRowInd - 1]->Cells["LineType"]->Value;
m_dtGridDataTable->Rows->InsertAt(dr, nCurrRowInd);
m_dtGridDataTable->EndLoadData();

dgItems->Rows->Refresh(RefreshRow::ReloadData);
dgItems->Rows->Refresh(RefreshRow::RefreshDisplay);

dgItems->ActiveCell = dgItems->Rows[nCurrRowInd]->Cells["LineType"];
}
catch(Exception^ ex) { throw ex; }
finally { }
}

The above code inserts a new line in the Datatable in required index position but the grid has at last.

I am doing sorting in the "dgItems_AfterSortChange" event and the grid property is set as 

dgItems->DisplayLayout->Override->HeaderClickAction = HeaderClickAction::ExternalSortSingle

Please someone help to insert the new line in the same position in both Grid and DataTable.

Thanks,

Dhanasekaran G

  • 4032
    Suggested Answer
    Offline posted

    Hello,

    if your datatable is bound to the grid, adding rows to the datatable is reflected in the grid automatically.

    The order of rows in the datatable are independent of order in the grid. To sort the grid, you can add some columns to the sorted-columns collection of each band.

    band.SortedColumns.Add( col );

    Regards

    Markus