I have an issue where I want to merge cells in a Row not a Column. I'll explain my situation;
I have a grid of questions and responses. Some questions do not have a response, so I want to merge the question and reponse cells together so that the question text spans across both cells. There is a 3rd column in the grid with comments in as shown below;
I want the cell highlighted in yellow to merge or span to 2nd cell. I still want this to behave as a row because there is data in the Comment column to write back to the database.
Please can someone tell me if this is possible?
The grid has no functionality built-in for merging cells in the same row. So there's no easy way to do this.
One way you could do it is to use RowLayouts and have 2 cells occupying the same space and then only show one or the other.
In other words, you would hav 4 columns in your grid: Question, Response, Comment, and MergedQuestionResponse.
In the RowLayout, but default, the columns would be set up like this:
Question
OriginX = 0
OriginY = 0
SpanX = 2
SpanY = 2
Response
OriginX = 2
Comment
OriginX = 4
When you add the new MergedQuestionResponse column, you would set it up like this:
MergedQuestionResponse
SpanX = 4
With a SpanX of 4 and the same Origin as the Question column, this column would exist in the same place that the existing two columns (Question and Response) exist.
Then, in the InitializeRow event of the grid, you set the hidden property on three cells in the row. If you want a split that shows two columns, then you make sure hidden is false on the Question and Response cells and that hidden is true on the MergedQuestionAndResponse cell. If you want to show merged data, then you reverse the hidden settings.
You will also need to handle copying the value from the two cells into the one cell and vice versa.
Hi Mike,
Please provide a sample for the above solution. I am not able to find the solution . We are currenlty using WinGrid 2006 version.
Please help to resolve the issue.
Problem: I have two column headers First Name , Last Name. That should be merged as "Name"
First Name Last Name
JIJIL I
Ram Krishan
Output required
Name
Thanks,
JIJIL
Hi,
I am using 2006 version . The code that i have used is below. Please let me know what all changes i have to do.
As mentioned in the above mail. I have two columns, First Name and Last Name and should now be merged as Name
Below code is inside the initilalize_layout event.
ultraGrid1.DisplayLayout.Bands[0].Columns[0].RowLayoutColumnInfo.OriginX = 0;
ultraGrid1.DisplayLayout.Bands[0].Columns[0].RowLayoutColumnInfo.OriginY = 0;
ultraGrid1.DisplayLayout.Bands[0].Columns[0].RowLayoutColumnInfo.SpanX = 4;
ultraGrid1.DisplayLayout.Bands[0].Columns[0].RowLayoutColumnInfo.SpanY = 2;
ultraGrid1.DisplayLayout.Bands[0].Columns[1].RowLayoutColumnInfo.OriginX = 0;
ultraGrid1.DisplayLayout.Bands[0].Columns[1].RowLayoutColumnInfo.OriginY = 0;
ultraGrid1.DisplayLayout.Bands[0].Columns[1].RowLayoutColumnInfo.SpanX = 0;
ultraGrid1.DisplayLayout.Bands[0].Columns[1].RowLayoutColumnInfo.SpanY = 0;
Have you read my example above? Maybe you missed the post where I explained this. But in my example above, there are 3 columns, not 2. You need a new unbound column to do the spanning. And you would never use all 0's for the spans of any of the columns.
The idea is that you have the two columns, just as they already are. Then you have an unbound column that spans the same space as both of the "real" columns. Then you show one of the other in each row, as you like.
If I want to use the new wizbang WinControlContainerEditer to place any control into a merged set of row cells, I must do the same? No cleaner way?
Thx.
dgennetten said:If I want to use the new wizbang WinControlContainerEditer to place any control into a merged set of row cells, I must do the same? No cleaner way?
If you are using CellMerging to merge cells in the same column, but different rows, then you don't need to do anything special.
If you are trying to merge cells within the same row (but different columns), then yes, you would have to use the technique I described here.
The type of editor you are using really doesn't matter.
Mike,
Is there still no added functionality to merge cells in the same row, you need to use the Row Layout trick you displayed above?
ChrisBrooks said:Is there still no added functionality to merge cells in the same row, you need to use the Row Layout trick you displayed above?
That is correct, there is no built-in functionality in the grid to merge cells in the same row.