473,385 Members | 1,888 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 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 12128
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: milk-jam | last post by:
I'm trying to set my datagridview so that the first row will be left blank and to use it as a filtering filed for the datagridview. Until now I was using 2 datagridview the upper one with a header...
1
by: cc | last post by:
Hi, using the DataGridView (.NET 2005) : I have a row currently selected in the Grid (say the 3rd row showing 'Product3') Now, when I click on a column to sort the records is the 'Product3'...
1
by: sapkal.manish | last post by:
Question : How can I find actual row position of DataTable in DataGridView when DataTable is sorted / My source code like this Private WithEvent dgvInwDet as new DataGridView Private...
4
by: Matt | last post by:
I have been searching all over the web for a way to sort a DataGridView based on the actual text being shown in a ComboBox column as opposed to the underlying value (an ID in this case). Can anyone...
3
by: joey.powell | last post by:
I have a datagridview where I set its "DataSource" property to a DataSet and its "DataMember" property to a table within the DataSet. I need for the DataGridView to "sort" through the contents of...
2
by: tee | last post by:
Hi, How do i sort datagridview programmically, current i have the following code but i keep get the error saying "DataGridView control must be bound to an IBindingList object to be sorted.", ...
2
by: Rick | last post by:
VS 2005/Pro I'm using a DataGridView in a Windows form and allowing the user to sort the columns by clicking on the header column. Is there some method offered by the grid to return back to...
0
by: Chris | last post by:
I have a DataGridView in a form that will display the information from various DataTables in my DataSet. The user is provided a list of tables and when they select a table name, the DataGridView...
0
by: Hassan | last post by:
Hi, Im using visual studio 2005,C#2 Framework 2.0 In my program, i have a DataGridView where DataGridView.DataSource equal to a BindingSource.DataSource and this BindingSource.DataSource equalt...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.