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.
Unfortunately, activation email could not send to your email. Please try again.

Data Alignment question/problem

Thread ID:

Created:

Updated:

Platform:

Replies:

58288 Mar 21,2007 01:10 PM Mar 28,2007 06:11 AM Windows Forms 6
loading
Tags: GridControl
Philip Bishop
Asked On March 21, 2007 01:10 PM

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

Administrator [Syncfusion]
Replied On March 21, 2007 03:38 PM

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.

Philip Bishop
Replied On March 21, 2007 03:54 PM

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???

Administrator [Syncfusion]
Replied On March 21, 2007 04:46 PM

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

Philip Bishop
Replied On March 26, 2007 01:10 PM

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?

Philip Bishop
Replied On March 27, 2007 10:18 AM

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?

Administrator [Syncfusion]
Replied On March 28, 2007 06:11 AM

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

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;