locked
DataGrid merge cells in WPF RRS feed

  • Question

  • Hello to everybody.

    I have a grid, which is used to display data (there're about 16 columns and 100 rows) . This way of displaying data was used to make possible cell merging (RowSpan/ColumnSpan) and each cell presents TextBox.

    But it's  resource-intensive. I would like to use datagrid, but how to make cell merging? Or another control which won't be resource-intensive.

     By the way, I have to create it dynamically.

     

    Best regards.

    Monday, November 15, 2010 6:17 PM

Answers

All replies

  • Hi ArtKey

    Welcome to our forum. I am glad to discuss this issue with you.

    I think if you change your Grid to DataGrid will not resolve your "Merge Cell" problem, because we usually do is to define DataGridColumns or generate a column by DataGrid according to the items. So the columns are fixed, any cells can not span other columns.

    I think this solution is not work on your issue.

    Another solution is DataGridView, but this method need some codes to complete "Merge Cell", I think you can refer to those link to achieve your goal.

    http://social.msdn.microsoft.com/forums/en-US/vbinterop/thread/5b659cbd-7d29-4da4-8b38-5d427c3762e2

    http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/9b85339d-d01e-4947-9a8d-fab87a85732d/

    http://social.msdn.microsoft.com/forums/en-US/winformsdatacontrols/thread/fea3dcff-5447-450a-8f7c-bb1c4f63371d/

    There are so many community members having the similar questions with yours.

    Hope it can help you.

     

    Best regards,

    Sheldon _Xiao 


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework!
    Wednesday, November 17, 2010 3:07 AM
  • Hi Sheldon _Xiao. Thank you for your reply. 

    I need to solve my problem in WPF not winforms where DataGridView is located. May be you mentioned something else?

    By the way cell merging is need just in first 2 rows and first 3 columns. As a solution it can be a usual grid with textboxes and a datagrid for displaing cells without any cell merging. 

    Wednesday, November 17, 2010 5:18 AM
  • Hi ArtKey

    Thank you for your feedback. I understand more details about your concern.

    I am sorry that I cannot explain clearly about DataGridView.

    Yes, you said right, DataGridView is a WinForms control not WPF, but we can use WinForms control in WPF, there is a lot of technic articles on it.

    If you the first solution is not fit for you, you can try to this whether it can resolve your issue, you can refer to this link:

    http://www.viblend.com/products/net/wpf/controls/data-grid.aspx

    On the other hand, you said:

    -->As a solution it can be a usual grid with textboxes and a datagrid for displaing cells without any cell merging?

    Do you mean your issue can be resolved by a Grid and a DataGrid ?

    If it can resolve your problem, could you kindly elaborate your problem now, and tell me what is your root concern is.

    This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

     

    Best regards,

    Sheldon _Xiao 


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework!
    Wednesday, November 17, 2010 6:48 AM
  • Hi Sheldon _Xiao. I know that I can place Datagridview in WPF control, but not in my case. I have to use wpf control only because of different reasons.

    I have read about Viblend datagrid even before posting my question. But it is not for free.

    About
    -->As a solution it can be a usual grid with textboxes and a datagrid for displaing cells without any cell merging?

    I wanted to say that I need cell merging just for row and column headers. But other cells don't need merging. So in my case it is best solution I think.



    Sorry for my english,it's not my native language
    Thursday, November 18, 2010 11:33 AM
  • Hi ArtKey

    As for your merging Column Header, I can achieve it use DataGridTemplateColumn in the DataGrid. I code a sample demonstrating you how to do complete it.

    You can download my code from this link:

    http://cid-41e44c402aaada87.office.live.com/self.aspx/For%20ArtKey/DataGridColumnMergeSample.rar

    As for your merging row, I am not sure what your concern is. If you want to merge their data, I think you can use RowDetailsTemplate to resolve your problem, for details you can refer to:

    http://msdn.microsoft.com/en-us/library/system.windows.controls.datagrid.rowdetailstemplate.aspx

     

    Best regards,

    Sheldon _Xiao


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework!
    • Marked as answer by ArtKey Friday, November 19, 2010 5:22 AM
    Friday, November 19, 2010 3:04 AM
  •  

    Thank you Sheldon _Xiao, It seems to be exactly what I needed. (Just to see what I needed: CellMerging

    with thanks from Russia.

     

     

    Friday, November 19, 2010 5:21 AM
  • Hi Russia

    I am glad to hear that this sample can help you.

    If you have any difficulty in future programming, welcome back.

     

    Best regards,

    Sheldon _Xiao


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework!
    Friday, November 19, 2010 7:08 AM
  • Hi ArtKey

    As for your merging Column Header, I can achieve it use DataGridTemplateColumn in the DataGrid. I code a sample demonstrating you how to do complete it.

    You can download my code from this link:

    http://cid-41e44c402aaada87.office.live.com/self.aspx/For%20ArtKey/DataGridColumnMergeSample.rar

    As for your merging row, I am not sure what your concern is. If you want to merge their data, I think you can use RowDetailsTemplate to resolve your problem, for details you can refer to:

    http://msdn.microsoft.com/en-us/library/system.windows.controls.datagrid.rowdetailstemplate.aspx

     

    Best regards,

    Sheldon _Xiao


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework!

    Hi Sheldon _Xiao,

    I tried increasing the column header text (Content1 - Content3) and details but it seems that the merged data grid breaks. Any ideas on how to fix this? Thank you.


    Sunday, December 23, 2012 1:21 PM
  • I am unable to download the merge column headers sample sample from the above link.

    The link is broken.

    Monday, March 10, 2014 10:32 AM
  • Hi

    i was googleng on how to merge headers in datagrid in wpf i saw your post but the link is not working any more can u pls provide a new link

    Thx

    Saturday, September 6, 2014 4:06 PM
  • Google again.

    Codeproject 13894 merging datagrid header columns

    I can't cut and paste from this tablet.

    You're best starting a new thread rather than trying to revive a dead one. People don't read answered threads.


    Hope that helps
    Please don't forget to up vote answers you like or which help you and mark one(s) which answer your question.

    Saturday, September 6, 2014 7:28 PM