Click here to Skip to main content
15,899,313 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: DataReader with SQL Join Pin
Johan Hakkesteegt2-Feb-12 23:35
Johan Hakkesteegt2-Feb-12 23:35 
AnswerRe: DataReader with SQL Join Pin
Dave Kreskowiak3-Feb-12 2:28
mveDave Kreskowiak3-Feb-12 2:28 
Questionvb.net Pin
Member 82843502-Feb-12 18:58
Member 82843502-Feb-12 18:58 
AnswerRe: vb.net Pin
Simon_Whale2-Feb-12 21:50
Simon_Whale2-Feb-12 21:50 
AnswerRe: vb.net Pin
Eddy Vluggen3-Feb-12 0:22
professionalEddy Vluggen3-Feb-12 0:22 
QuestionCopy Content from Word Docuemnt to RichBox Pin
Peace4all2-Feb-12 17:50
Peace4all2-Feb-12 17:50 
AnswerRe: Copy Content from Word Docuemnt to RichBox Pin
Wayne Gaylard2-Feb-12 19:19
professionalWayne Gaylard2-Feb-12 19:19 
Questionshow/hide datagridview rows by setting trackbar value Pin
bezkintos2-Feb-12 14:09
bezkintos2-Feb-12 14:09 
Hi.
I need a help with showing/hiding rows in datagridview by setting the trackbar value. The below example works if there are not too much rows. If there are greater number of rows then after you change a value of trackbar you must wait for a few seconds for the datagridview to redraw and only then you can use trackbar again...
Apparently I must use multithreading to achieve what I want: when I use trackbar, datagridview starts to redraw, but if I use trackbar again before datagridview finishes redrawing, it immediately stops redrawing according to previous trackbar value and starts to redraw from the beginning according to current trackbar value. That way trackbar will never be frozzen (stuck, unusable...).
I tried with backgroundworker but got error "Cross-thread operation not valid: Control '' accessed from a thread other than the thread it was created on." - Maybe didn't use it right?

P.S. I have old and slow computer. If you have new and fast computer maybe you wont experience what I'm describing here so try to increase number of added rows in line 'For i As Integer = 1 To 5000' (I added 5000 rows here) - and if you have even older and slower computer than you will have to decrease this value or you will have to wait to long after you drag the thumb in trackbar.

VB
Public Class Form1

    WithEvents trackbar1 As New TrackBar
    WithEvents DataGridView1 As New DataGridView
    Dim label1 As New Label

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

        'trackbar
        Me.Controls.Add(trackbar1)
        trackbar1.Location = New Point(0, 150)
        trackbar1.Size = New Size(220, 140)
        trackbar1.Maximum = 40
        trackbar1.LargeChange = 1
        trackbar1.SmallChange = 1
        AddHandler trackbar1.Scroll, AddressOf TrackBar1_ScrollHandler

        'labels
        Me.Controls.Add(label1)
        label1.Location = New Point(0, 200)
        label1.Size = New Size(220, 140)
        label1.Text = "Only rows with values in Column2 greater than 0 are visible"

        'datagridview
        Me.Controls.Add(DataGridView1)
        DataGridView1.Location = New Point(0, 0)
        DataGridView1.Size = New Size(220, 140)
        DataGridView1.AllowUserToAddRows = False
        DataGridView1.RowHeadersVisible = False
        DataGridView1.TabIndex = 1

        'adding columns
        Dim column1 = New DataGridViewTextBoxColumn()
        column1.Name = "Column 1"
        column1.ValueType = GetType(System.DateTime)
        column1.ReadOnly = True
        DataGridView1.Columns.Add(column1)
        Dim column2 = New DataGridViewTextBoxColumn()
        column2.Name = "Column 2"
        column2.ValueType = GetType(System.Int64)
        column2.ReadOnly = True
        DataGridView1.Columns.Add(column2)

        'adding example data
        Dim rnd1 As New Random
        For i As Integer = 1 To 5000
            DataGridView1.Rows.Add(DateSerial(2011, rnd1.Next(1, 12), rnd1.Next(1, 28)), rnd1.Next(0, 40))
        Next

    End Sub

    Private Sub TrackBar1_ScrollHandler(sender As System.Object, e As System.EventArgs)

        For i As Long = 0 To (DataGridView1.Rows.Count - 1)
            If DataGridView1.Rows(i).Cells("Column 2").Value < trackbar1.Value Then
                DataGridView1.Rows(i).Visible = False
            Else
                DataGridView1.Rows(i).Visible = True
            End If
        Next

        label1.Text = "Only rows with values in Column2 greater than " + trackbar1.Value.ToString + " are visible"

    End Sub
End Class

AnswerRe: show/hide datagridview rows by setting trackbar value Pin
Luc Pattyn2-Feb-12 15:07
sitebuilderLuc Pattyn2-Feb-12 15:07 
GeneralRe: show/hide datagridview rows by setting trackbar value Pin
bezkintos3-Feb-12 11:51
bezkintos3-Feb-12 11:51 
GeneralRe: show/hide datagridview rows by setting trackbar value Pin
Alan N3-Feb-12 13:01
Alan N3-Feb-12 13:01 
GeneralRe: show/hide datagridview rows by setting trackbar value Pin
bezkintos3-Feb-12 14:43
bezkintos3-Feb-12 14:43 
AnswerRe: show/hide datagridview rows by setting trackbar value Pin
Luc Pattyn4-Feb-12 3:30
sitebuilderLuc Pattyn4-Feb-12 3:30 
GeneralRe: show/hide datagridview rows by setting trackbar value Pin
bezkintos4-Feb-12 6:22
bezkintos4-Feb-12 6:22 
AnswerRe: show/hide datagridview rows by setting trackbar value Pin
Luc Pattyn4-Feb-12 6:43
sitebuilderLuc Pattyn4-Feb-12 6:43 
GeneralRe: show/hide datagridview rows by setting trackbar value Pin
bezkintos4-Feb-12 7:51
bezkintos4-Feb-12 7:51 
AnswerRe: show/hide datagridview rows by setting trackbar value Pin
Luc Pattyn4-Feb-12 8:02
sitebuilderLuc Pattyn4-Feb-12 8:02 
GeneralRe: show/hide datagridview rows by setting trackbar value Pin
bezkintos4-Feb-12 8:34
bezkintos4-Feb-12 8:34 
AnswerRe: show/hide datagridview rows by setting trackbar value Pin
Luc Pattyn4-Feb-12 9:19
sitebuilderLuc Pattyn4-Feb-12 9:19 
Questionhaving trouble replacing Trademark and Registered symbol with Regex Pin
David Mujica2-Feb-12 6:18
David Mujica2-Feb-12 6:18 
AnswerRe: having trouble replacing Trademark and Registered symbol with Regex Pin
Luc Pattyn2-Feb-12 9:05
sitebuilderLuc Pattyn2-Feb-12 9:05 
QuestionADO.net Pin
Amanjot1-Feb-12 12:09
Amanjot1-Feb-12 12:09 
AnswerRe: ADO.net Pin
Eddy Vluggen1-Feb-12 12:21
professionalEddy Vluggen1-Feb-12 12:21 
QuestionCreate a unique Id for each row of table Pin
Seema Bawa1-Feb-12 8:19
Seema Bawa1-Feb-12 8:19 
AnswerRe: Create a unique Id for each row of table Pin
Simon_Whale1-Feb-12 12:16
Simon_Whale1-Feb-12 12:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.