We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Data Alignment question/problem

I've attached a sample I have a question about. In the sample I have a grid that by clicking button1 loads 3 rows of zeros. Notice the alignment of the zeros after the load. Now if you click button2 it will load a total of 7 rows of zeros. Notice how the last 4 rows are aligned differently then the original 3. Also the last 4 rows seem to lose every other grid setting I had. For instance you cant type a negative number in the first 3 rows but in the last 4 you can. I would think these would stay the same and that I would not have to set every setting each time for each row. I can't seem to figure out how to fix this. I am sure it is something simple and I am missing it.

Data Alignment.zip

6 Replies

AD Administrator Syncfusion Team March 21, 2007 07:38 PM UTC

Hi Philip,

Instead of setting the RowCount property, try calling the Hidden.SetRange method (button1.Click event) to hide/show the specified range of rows in a grid.

[C#]
//Button1.Click event.
C1.Rows.Hidden.SetRange(5, GC1.RowCount, True)

//Button2.Click event.
C1.Rows.Hidden.SetRange(5, GC1.RowCount, False)

Best regards,
Haneef

Note:
The reason for getting this behavior is that you are setting the rowcount property to 4 in a button1.Click event. Setting the rowcount property automatically removes the rows and its styles from the grid.


PB Philip Bishop March 21, 2007 07:54 PM UTC

So is there any way that I can just reinitialize the grid to the way it was when the form loads? So the first thing that would happen when they click button2 is it would reinitialize the grid to the way it was when the form loaded and then this problem wouldn't happen???


AD Administrator Syncfusion Team March 21, 2007 08:46 PM UTC

Hi Philip,

One way you can do this by calling SaveXml method to serialize the GridControl in button1.Click event and then reload Xml file using the GridControl.InitializeFromXml() in Button2.Click event. You can refer this forum for more details. Please let me know if this helps.

Best regards,
Haneef


PB Philip Bishop March 26, 2007 05:10 PM UTC

Ok so in testing this some more I've noticed something else. You say that my problem is that I changed the row count and that it messed up the styles. So if that is the case then wouldn't changing the col count also mess up the styles? I changed my sample to set the col count to a number and then reset it using a button to a bigger number and did not get the same outcome of data alignment as I do changing the rows. Would I not get the same outcome by changing the col count in a button as I do changing the row count?


PB Philip Bishop March 27, 2007 02:18 PM UTC

Also, in testing it appears that the XML seems slow and causes the grid to flicker. So how come changing col count doesn't have the same behavior as changing the row count does?


AD Administrator Syncfusion Team March 28, 2007 10:11 AM UTC

Back to your original sample, in your button handler 1, make the code read like

GC1.BeginUpdate()
GC1.RowCount = 2
GC1.RowCount = 4

Then I think you will see what is going on. When you lower the row count, it throws away all the rows above that count, and this includes any row styles that you have set earlier. So, when you later increase the rowcount, it does not use your original row styles that were set earlier and thrown away, instead it uses the default style settings.

This also explains why changing the column count does not affect this. Removing columns does not change any row styles.

One way around this is to cache a 'default' rowstyle that you want to apply to every new row. Here is your button handler 2 modified to apply whatever rowstyle is associated with row#2 (the first 'regular" row in your grid to all rows that do not have a rowstyle assigned to them. The rowstyle lives in data(rowIndex, -1).


Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim i, j As Integer
Windows.Forms.Cursor.Current = Cursors.WaitCursor
GC1.BeginUpdate()
GC1.RowCount = 8
Dim defaultRowStyleStore As Syncfusion.Windows.Forms.Grid.GridStyleInfoStore = data(2, -1)
For i = 2 To 8 ''Row
If data(i, -1) Is Nothing Then
data(i, -1) = defaultRowStyleStore
End If
For j = 1 To 64 ''Col
If Not data(i, j) Is Nothing Then
style = New Syncfusion.Windows.Forms.Grid.GridStyleInfo(data(i, j))
style.CellTipText = "data_2" + " " + style.CellTipText
Else
style = New Syncfusion.Windows.Forms.Grid.GridStyleInfo
style.CellTipText = "new_2"
End If
With style
.CellValue = 0
data(i, j) = .Store
End With
Next j
Next i
GC1.CurrentCell.MoveTo(GC1.CurrentCell.RowIndex, GC1.CurrentCell.ColIndex)
GC1.EndUpdate()
GC1.Refresh()
GC1.Focus()
Windows.Forms.Cursor.Current = Cursors.Default
End Sub

Loader.
Live Chat Icon For mobile
Up arrow icon