Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #14385 |

    Hi All,

    I have a simple problem to insert new Row by index.

    In case of table, it provides method InsertAt(index), but there is no that kind of method in Xceed Grid.

    How to insert row by using index value?

    Many thanks

    Imported from legacy forums. Posted by JKim (had 6681 views)

    User (Old forums)
    Member
    Post count: 23064

    I don’t actully believe there is a way of doing this.

    I’ve seen this before and I think if my memory serves me right the Xceed guys said that you’ll need to add a column with incrementing numbers and sort on that column.
    When you want to insert then put the row number where it should go and I guess increment all the other numbers below it.

    I maybe wrong and/or it may be fixed in version 3.0 of the grid. I would hope so.

    Imported from legacy forums. Posted by Chris (had 389 views)

    User (Old forums)
    Member
    Post count: 23064

    If you look here:
    http://www.xceedsoft.com/Forums/ShowPost.aspx?PostID=1443
    Other poeple have got similar problems and the work around isn’t great.

    Imported from legacy forums. Posted by Chris (had 290 views)

    User (Old forums)
    Member
    Post count: 23064

    Yes, there is no way to insert row by any specific index.

    I hope, it will be implemented next version of Xceed Grid.

    Thanks for all replyers..

    Many thanks.

    Imported from legacy forums. Posted by JKim (had 448 views)

    Xceed Support
    Member
    Post count: 5658

    Hi all, data rows section in the grid can be custom sorted at will, meaning you have the full control on the order of data rows.

    Unless overridden, the default order of data rows is the one in witch they are added in unbound mode, or in the order of the data returned from the database if bound, this is to allow sorting and grouping functionality.

    In the case you are in unbound mode or if you are managing your data yourself, you could use value rows (in fixed sections) instead of data rows and have full insert and other flexibility capabilities.

    Imported from legacy forums. Posted by Vince [Xceed] (had 702 views)

    User (Old forums)
    Member
    Post count: 23064

    But you have to agree that that’s still not the best solution.

    Imported from legacy forums. Posted by Chris (had 411 views)

    User (Old forums)
    Member
    Post count: 23064

    To insert row by any specific index, I was thinking to add new row as template.
    like below ( drag & drop in Xceed Grid):
    There is two rows which are from row and target row.
    This way is the best choice to me.
    Any other ideas? Please let me know.

    private void Drag_Drop( object sender, DragEventArgs e )
    {

    Xceed.Grid.DataRow targetRow= ((Xceed.Grid.Cell)sender).ParentRow as Xceed.Grid.DataRow;
    int targetIndex = this.gridControl1.DataRows.IndexOf(targetRow);
    this.gridControl1.CurrentRow = this.gridControl1.DataRows[targetIndex];

    int fromRowIndex = this.index; // member variable index represents from row’s index

    if( (this.index – targetIndex) > 0 ) //from row index is greater than target row index
    {
    for ( int i = 0 ; i < this.index – targetIndex ; i ++)
    {
    Xceed.Grid.DataRow temp = this.gridControl1.DataRows.AddNew();
    temp.Cells[0].Value = this.gridControl1.DataRows[fromRowIndex].Cells[0].Value;
    temp.Cells[1].Value = this.gridControl1.DataRows[fromRowIndex].Cells[1].Value;
    temp.Cells[2].Value = this.gridControl1.DataRows[fromRowIndex].Cells[2].Value;

    this.gridControl1.DataRows[fromRowIndex].Cells[0].Value= this.gridControl1.DataRows[fromRowIndex – 1].Cells[0].Value;
    this.gridControl1.DataRows[fromRowIndex].Cells[1].Value=this.gridControl1.DataRows[fromRowIndex-1].Cells[0].Value;
    this.gridControl1.DataRows[fromRowIndex].Cells[2].Value=this.gridControl1.DataRows[fromRowIndex-1].Cells[0].Value;

    this.gridControl1.DataRows[fromRowIndex-1].Cells[0].Value= temp.Cells[0].Value;
    this.gridControl1.DataRows[fromRowIndex1].Cells[1].Value=temp.Cells[1].Value;
    this.gridControl1.DataRows[fromRowIndex-1].Cells[2].Value=temp.Cells[2].Value;
    temp.Remove();
    index_count –;

    }

    }
    else
    {
    for ( int i = 0 ; i < targetIndex – this.index ; i ++)
    {
    Xceed.Grid.DataRow temp = this.gridControl1.DataRows.AddNew();
    temp.Cells[0].Value = this.gridControl1.DataRows[fromRowIndex].Cells[0].Value;
    temp.Cells[1].Value = this.gridControl1.DataRows[fromRowIndex].Cells[1].Value;
    temp.Cells[2].Value = this.gridControl1.DataRows[fromRowIndex].Cells[2].Value;

    this.gridControl1.DataRows[fromRowIndex].Cells[0].Value= this.gridControl1.DataRows[fromRowIndex+1].Cells[0].Value;
    this.gridControl1.DataRows[fromRowIndex].Cells[1].Value=this.gridControl1.DataRows[fromRowIndex+1].Cells[0].Value;
    this.gridControl1.DataRows[fromRowIndex ].Cells[2].Value=this.gridControl1.DataRows[fromRowIndex+1].Cells[0].Value;

    this.gridControl1.DataRows[fromRowIndex + 1].Cells[0].Value= temp.Cells[0].Value;
    this.gridControl1.DataRows[fromRowIndex+1].Cells[1].Value=temp.Cells[1].Value;
    this.gridControl1.DataRows[fromRowIndex+1].Cells[2].Value=temp.Cells[2].Value;
    temp.Remove();
    index_count ++;
    }

    }

    }

    Imported from legacy forums. Posted by JKim (had 705 views)

    User (Old forums)
    Member
    Post count: 23064

    What maybe easier is what I said before. The problem with this solution maybe that copying may take too long depending on how many rows there are. Imagine you have 10000 rows and you want to insert a row at index 2, that means you need to copy nearly 30000 bits of data around instead of nearly 10000 if you have a single column that is your index column, granted that is still too much messing around. You can still make that key column invisible and sort on it though.

    The other thing you could do is implement custom databinding on a non-dataset object. That way you can make changes at an instant by overrideing the indexer of the IList or IBinding list property of whatever object you have.

    Imported from legacy forums. Posted by Chris (had 497 views)

    User (Old forums)
    Member
    Post count: 23064

    Yes, you are right, but suppose, there number of hidden invisible, how to access the way,
    please give me more detail example.

    Many thanks.

    Imported from legacy forums. Posted by JKim (had 381 views)

    User (Old forums)
    Member
    Post count: 23064

    Well you’ll have an index column that is invisible. You can still access it through code and when you want to insert a row increment all the row indexes of that column that will be below the new row and then just add it ensuring that the grid is sorted on that column.

    Imported from legacy forums. Posted by Chris (had 877 views)

    User (Old forums)
    Member
    Post count: 23064

    Has ANYONE got the drag and drop to work using the hidden sort column? I have the drag and drop functionality working, but using the hidden column in order to index the rows is not working. I was told from Xceed support to:

    When you want to insert a row at a specific index, set the row’s hidden cell’s value to the position and increase the other rows’ cells value by 1.

    I’ve tried this and it doesn’t seem to work. Sometimes it works for the first drag and drop, but when I try to drag and drop another row, it’s like it’s confused and the values in the sort column get all screwed up. If anyone has this working please post your working code in here for those of us stuck with trying to implement this feature which one would think should already be part of the control.

    Why can’t you set the .Index property of the grid control? Why is it read-only?

    For the next release why don’t you either implement an easier way to drag and drop rows, like you have done for columns…that is built in and works fine. Why don’t you make the grid handle row drag and drop? Or allow us to at least set the row’s index property.

    Thanks,

    Nathan

    Imported from legacy forums. Posted by Nathan (had 7972 views)

Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.