471,330 Members | 1,827 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,330 software developers and data experts.

Datagridview Remove Sort

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 ?

Jan 13 '06 #1
1 11817
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

Jan 14 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by milk-jam | last post: by
1 post views Thread by sapkal.manish | last post: by
3 posts views Thread by joey.powell | last post: by
reply views Thread by Chris | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.