I have a class wherein I am storing all the values of FileALine
and FileBLine
properties into a list called Changes
The code for the properties is as shown below.
public class Result
{
public Result()
{
this.Changes = new List<Difference>();
}
public IList<Difference> Changes { get; set; }
}
public class Differences
{
public int LineNumber { get; set; }
public string FileALine { get; set; }
public string FileBLine { get; set; }
}
I am calling the Changes
list from a form to populate a Synfusion GridControl. It has two Columns DataRow
and Details
. Right now I am only able to fill in either FileAline
values or FileBLine
values into the second column.
I am unable to figure out how to display both FileAline
values on one line and FileBLine
values in the next line as shown in the image below.
public partial class Form: Form
{
private void DisplayValues(Result result)
{
if (result != null && result.Changes.Count > 0)
{
var differences = result.Changes;
this.detailsGridControl.RowCount = differences.Count;
this.detailsGridControl.ColCount = 2;
for (var i = 0; i < differences.Count; i++)
{
var detailsA = differences[i];
var row = i + 1;
this.detailsGridControl[row, (int)FormColumns.DataRow].Text = detailsA.LineNumber.ToString();
this.detailsGridControl[row, (int)FormColumns.Details].Text = detailsA.FileALine;
this.detailsGridControl[row, (int)FormColumns.Details].Text = detailsA.FileBLine;
}
}
}
}
So the output must be something like this.
Any suggestions on how to achieve this?
Thanks in advance!
Please try the below suggestions.
Suggestion 1
In the DisplayValues() method of Form, you are trying to set the FileALine and FileBLine for the same cell. So, the CellValue will be overridden and returns only FileBLine only. In order to set the CellValue from list, the PopulateValues() method can be used. Refer to the below code and sample,
Dim difference As New List(Of Differences)()
difference.Add(New Differences() With {.LineNumber = 1, .FileALine = `"FileLineA", .FileBLine = "FileLineB"})
difference.Add(New Differences() With {.LineNumber = 2, .FileALine = "FileLineB", .FileBLine = "FileLineA"})
Dim r As New Result()
For Each d As Differences In difference
r.Changes.Add(New Data() With {.DataRow = d.LineNumber, .Details = d.FileALine})
r.Changes.Add(New Data() With {.DataRow = d.LineNumber, .Details = d.FileBLine})
Next d
Me.gridControl1.PopulateHeaders(GridRangeInfo.Cells(0, 1, gridControl1.RowCount, gridControl1.ColCount), r.Changes)
Me.gridControl1.PopulateValues(GridRangeInfo.Cells(1, 1, gridControl1.RowCount, gridControl1.ColCount), r.Changes)
Me.gridControl1.Refresh()
Suggestion 2
You can also set the CellValue by Text property of GridStyleInfo class. refer to the sample,
Dim difference As New List(Of Differences)()
difference.Add(New Differences() With {.LineNumber = 1, .FileALine = "FileLineA", .FileBLine = "FileLineB"})
difference.Add(New Differences() With {.LineNumber = 2, .FileALine = "FileLineB", .FileBLine = "FileLineA"})
Dim r As New Result()
For Each d As Differences In difference
r.Changes.Add(New Data() With {.DataRow = d.LineNumber, .Details = d.FileALine})
r.Changes.Add(New Data() With {.DataRow = d.LineNumber, .Details = d.FileBLine})
Next d
DisplayValues(r)
Private Sub DisplayValues(ByVal result As Result)
If result IsNot Nothing AndAlso result.Changes.Count > 0 Then
Dim differences = result.Changes
Me.gridControl1.RowCount = result.Changes.Count
Me.gridControl1.ColCount = 2
For i = 0 To differences.Count - 1
Dim detailsA = TryCast(differences(i), Data)
Dim row = i + 1
Me.gridControl1(row, 1).Text = detailsA.DataRow.ToString()
'To set FileALine or FileBLine for column 2
Me.gridControl1(row, 2).Text = detailsA.Details
Next i
End If
End Sub
Note: you can create an object for the list to populate data as your convenient.