unvell / ReoGrid

Fast and powerful .NET spreadsheet component, support data format, freeze, outline, formula calculation, chart, script execution and etc. Compatible with Excel 2007 (.xlsx) format and working on .NET 3.5 (or client profile), WPF and Android platform.
https://reogrid.net
MIT License
1.33k stars 394 forks source link

How to adjust column order by dragging and dropping columns #512

Open hs205118 opened 11 months ago

hs205118 commented 11 months ago

Describe the feature

Hello, thank you for this great help in my program development. However, I have a feature that I don't know how to implement. Can you guide me?

I have columns A, B, C, and D. I hope to drag a column to the front or back of a specified column while holding down the top title of that column. Implement sorting methods such as A, C, D, and B.

And, my top customer header has a checkbox.

Which edition of ReoGrid is targeted

jingwood commented 11 months ago

This is not a feature that can be implemented easily.

Moving the data of a column can be straightforward, but if you have merged cells or borders, there should be processes for how to split or combine merged cells, and how to handle the borders. Additionally, if you have formulas, you need to consider how the formula references change.

We may consider implementing this feature in future versions, but it may take some time.

CanadianHusky commented 11 months ago

@hs205118 I agree with @jingwood. It can get very complicated depending on the existing structure of the Grid.

Here is my suggestion how I would implement Column Reorder without any changes to the control itself. 1- Hook an event handler to the Reogrid.Mouseup and watch for right click 2- On Mouse Right Click event, open your own Form/Control that has a basic Listview or Listbox with the current column names. Enable Drag & Drop for reorder on your own control. Example : https://stackoverflow.com/questions/805165/reorder-a-winforms-listbox-using-drag-and-drop. Keep track of internal Column display indexes when closing your Form. 3- Rebuild your Reogrid contents from the underlying data with own code, under consideration of DisplayIndexes of the columns. The Column headers in Reogrid allow renaming, so to the user it will look like the column position changed. You need a list or dictionary object that keeps track of and maps Datacolumn vs DisplayIndex.