Add Row Manually to DataGrid

D

DraguVaso

Hi,

I have a DataGrid to which I want the program add from time to time a new
row, without redrawing the whole DataGrid. So I don't want to add the new
Row to the DataSource and than do a Refresh, but I want it kind of directly
add it to the DataGrid so it only adds the new row.

Does anybody knows how to do this? Or what I'd better use for this?

The reason I want it is that repainting the (Custom)DataGrid takes some
time, and I don't want to repaint it the whole time when I Add a new Row
(every 5-6 seconds a new Row should be added).

Thanks a lot in advance,

Pieter
 
C

Cor Ligthert

Hi Pieter,

I try to get it clear to me, do you mean you want to set the datasource to
nothing and after that set it again, is that something you want to archieve?

:)

Cor
 
D

DraguVaso

Well I don't knwo really :)
I just have a DataGrid with like 20 rows in it. I have a process that is
turning, and that should add every 5 seconds a new Row to my DataGrid.

When the new Row is added, I don't want that it repaints the whole DataGrid,
but just adds the new row at the end of it.. :)
 
K

Ken Tucker [MVP]

Hi,

The datagrid will redraw itself when you add a row. Post your code
for the datagrid column style maybe we can help speed it up some.

Ken
-----------------------
Hi,

I have a DataGrid to which I want the program add from time to time a new
row, without redrawing the whole DataGrid. So I don't want to add the new
Row to the DataSource and than do a Refresh, but I want it kind of directly
add it to the DataGrid so it only adds the new row.

Does anybody knows how to do this? Or what I'd better use for this?

The reason I want it is that repainting the (Custom)DataGrid takes some
time, and I don't want to repaint it the whole time when I Add a new Row
(every 5-6 seconds a new Row should be added).

Thanks a lot in advance,

Pieter
 
C

Cor Ligthert

Hi Pieter,

I was curious and made this, in my idea this goes in batches, what is it you
want to archieve what you said, however it goins very smooth on this sunny
day here.

:)

Cor

Dim dt As DataTable
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
dt = New DataTable("Pieter")
dt.Columns.Add("Time", GetType(System.DateTime))
DataGrid1.DataSource = dt
Dim ts As New DataGridTableStyle
ts.MappingName = "Pieter"
Dim column As New DataGridTextBoxColumn
ts.GridColumnStyles.Add(column)
DataGrid1.TableStyles.Add(ts)
column.MappingName = "Time"
column.HeaderText = "Tijd"
column.Width = 50
column.Format = ("HH:mm:ss")
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Timer1.Tick
For i As Integer = 0 To 20
Dim dr As DataRow = dt.NewRow
dr(0) = Now
dt.Rows.Add(dr)
DataGrid1.ScrollToRow(dt.Rows.Count - 1)
Next
End Sub
End Class
Public Class MyDataGrid
Inherits DataGrid
Sub ScrollToRow(ByVal row As Integer)
If Not Me.DataSource Is Nothing Then
Me.GridVScrolled(Me, _
New ScrollEventArgs(ScrollEventType.LargeIncrement, row))
End If
End Sub
End Class
 
D

DraguVaso

Thanks Cor!
I tried it and indeed it goes very smooth, hehe :)
Once again I was looking to far and made it too complicated, hehe :)

Thanks a lot! And enjoy the sun overthere! Here below it's sunny too :)

Pieter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top