By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,285 Members | 1,659 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,285 IT Pros & Developers. It's quick & easy.

Add Row Manually to DataGrid

P: n/a
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
Nov 20 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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
Nov 20 '05 #2

P: n/a
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.. :-)

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:%2******************@TK2MSFTNGP09.phx.gbl...
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

Nov 20 '05 #3

P: n/a
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
-----------------------
"DraguVaso" <pi**********@hotmail.com> wrote in message
news:uf****************@TK2MSFTNGP11.phx.gbl...
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

Nov 20 '05 #4

P: n/a
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


Nov 20 '05 #5

P: n/a
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

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
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

Nov 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.