Hello,
Is it possible to disable sort temporarilty ? without changing current row ?
I want to add a row to a specific location. But if user sorted the
datagridview
row goes to a wrong position. That 's why before calling InsertAt() method i
want to remove current sorting. Is it possible ?
Where should the row be exactly placed?
Have in mind this could only be a really temporary state.
The User *wants* the Grid to be sorted (in this case)
Ok, what if you use the following. What do you wish?
//using AdrRow=DataFormAssist.AdventureWorksDataSet.Addres sRow;
DataGridView dgv = documentDataGridView;
DataRow dr = ((DataRowView)addressBindingSource.AddNew()).Row;
AdrRow adr = (AdrRow)dr;
adr.AddressLine1="Hallo1"; adr.AddressLine2="Hallo2";
adr.City = "MyCity"; addressBindingSource.EndEdit();
//========================
if you really want a that what you said, you
could bind to a newly created temporary DataTable like:
CurrencyManager cm = (CurrencyManager)BindingContext[
dgv.DataSource, dgv.DataMember];
DataTable dt = new DataTable("Temp");
foreach (DataGridViewColumn dgc in dgv.Columns)
dt.Columns.Add(dgc.DataPropertyName, dgc.ValueType);
int oldPosition = cm.Position;
DataRowView darv = ((DataRowView)addressBindingSource.AddNew());
AdrRow adr = (AdrRow)darv.Row;
adr.AddressLine1 = "Hello1"; adr.AddressLine2 = "Hello2"; adr.City = "MyCity";
DataRow yourNewRow = dt.NewRow();
yourNewRow.ItemArray = adr.ItemArray;
for (int r=0; r<cm.List.Count; r++)
{
DataRowView drv = (DataRowView)cm.List[r];
DataRow dr = dt.NewRow();
dr.ItemArray = drv.Row.ItemArray;
if (r == oldPosition) dt.Rows.Add(yourNewRow);
if (r != cm.Position) dt.Rows.Add(dr);
}
dgv.DataSource = dt; cm.Position = oldPosition;
dgv.CurrentCell = dgv.Rows[cm.Position].Cells[0];
ciao Frank
--
Dipl.Inf. Frank Dzaebel [MCP/MVP C#]
http://Dzaebel.NET