AllExperts > Experts 
Search      

VB.NET

Volunteer
Answers to thousands of questions
 Home · More Questions · Answer Library  · Encyclopedia ·
More VB.NET Answers
Question Library

Ask a question about VB.NET
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Syed Rizwan Muhammad Rizvi
Expertise
I can answers questions regarding web based and desktop based programming in VB.Net. Which can include SOAP, XML, Custom Controls, COM Interoperability etc.

Experience
Have been working in this specific area for last 2 years previously I was a VB 6 Developer with experties in other languages as well. Total 10 years of programming experience.

 
   

You are here:  Experts > Computing/Technology > Basic > VB.NET > First In, First Out in Datagridview

Topic: VB.NET



Expert: Syed Rizwan Muhammad Rizvi
Date: 6/27/2008
Subject: First In, First Out in Datagridview

Question
Hello Sir, I have a question in vb.net. I have written a program that could create 7 records in the datagridview. When I am able to enter the 8th record all the previous 7 records were getting cleared and started from the 1st record.
My question is, I dont want to clear all the records, instead I need a First In, First Out principle. That is, when I enter 8th record 1st record must get erased (sequencing it as 2 to 8), and when I enter 9th record 2nd record must be deleted ( 3 to 9), so on....

Can you please help me regarding this code, it is very urgent.

Below is the code with respect to the above question

Sub update1()

       If (count = 7) Then
           count = 0
       End If

       count = count + 1

       mac(count) = Main.TextBox2.Text
       m_size(count) = Main.TextBox3.Text
       speed(count) = Main.TextBox4.Text
       m_ba(count) = Main.TextBox5.Text

       m_pp(count) = Main.TextBox6.Text
       aa(count) = Main.TextBox12.Text
       fc(count) = Main.TextBox13.Text
       lc(count) = Main.TextBox14.Text

       If (Main.Panel8.Visible = True) Then
           ot(count) = Main.TextBox16.Text
       Else
           ot(count) = ""
       End If


       Dim comp As String
       comp = "Complement"

       cc.calculations()
       life(count) = cc.ttt.ToString
       Main.TextBox7.Text = Math.Round(cc.mc * 100) / 100
       cap(count) = Main.TextBox7.Text

       cph(count) = Math.Round(cc.g, 2)
       cpa(count) = Math.Round(cc.d_be, 2)

   End Sub
   

   Sub populate()
       'Me.DataGridView1.cle

       '       If count > 0 Then
       Dim j As Integer

       'DataGridView1.

       Me.DataGridView1.ColumnCount = 0
       Me.DataGridView1.Rows.Clear()
       Me.DataGridView1.ColumnCount = count + 1

       Me.DataGridView1.Columns(0).Name = "Complement"




       ' Me.DataGridView1.Columns.Add()
       'Next i


       For cc.i = 0 To 11
           Me.DataGridView1.Rows.Add()
           Me.DataGridView1.RowHeadersWidth = 120

       Next cc.i



       DataGridView1.Rows(0).Cells(0).Value = "Machine"
       DataGridView1.Rows(1).Cells(0).Value = "Size"
       DataGridView1.Rows(2).Cells(0).Value = "Speed"
       DataGridView1.Rows(3).Cells(0).Value = "Beginning Age"


       DataGridView1.Rows(4).Cells(0).Value = "Purchase Price ($)"
       DataGridView1.Rows(5).Cells(0).Value = "Capacity (Acres/hour)"

       DataGridView1.Rows(6).Cells(0).Value = "Annual Acres (Acres)"
       DataGridView1.Rows(7).Cells(0).Value = "Fuel Cost"
       DataGridView1.Rows(8).Cells(0).Value = "Labor Cost"
       DataGridView1.Rows(9).Cells(0).Value = "Other"

       DataGridView1.Rows(10).Cells(0).Value = "Expected Life (years)"
       DataGridView1.Rows(11).Cells(0).Value = "Total Cost per hour ($/hr)"
       DataGridView1.Rows(12).Cells(0).Value = "Total Cost per acre ($/acre)"

       'cc.type = Main.TextBox2.Text

       For j = 1 To count

           Me.DataGridView1.Columns(j).Name = "Complement " + j.ToString

           DataGridView1.Rows(0).Cells(j).Value = mac(j)
           DataGridView1.Rows(1).Cells(j).Value = m_size(j)
           DataGridView1.Rows(2).Cells(j).Value = speed(j)
           DataGridView1.Rows(3).Cells(j).Value = m_ba(j)
           DataGridView1.Rows(4).Cells(j).Value = m_pp(j)
           DataGridView1.Rows(5).Cells(j).Value = cap(j)
           DataGridView1.Rows(6).Cells(j).Value = aa(j)
           DataGridView1.Rows(7).Cells(j).Value = fc(j)
           DataGridView1.Rows(8).Cells(j).Value = lc(j)
           DataGridView1.Rows(9).Cells(j).Value = ot(j)

           DataGridView1.Rows(10).Cells(j).Value = life(j)
           'total cost
           DataGridView1.Rows(11).Cells(j).Value = cph(j)
           DataGridView1.Rows(12).Cells(j).Value = cpa(j)

       Next j
       '     End If

   End Sub

Answer
There are two ways:

1. If you want to keep the Rows indexing use DataGridView1.Rows(0).visible=False

2. if you dont then you can use Rows.RemoveAt(0) after which the 2nd row will become first one and would be accessible again using Rows(0).


regards,
Riz

Add to this Answer    Ask a Question



  Rate this Answer
   Was this answer helpful?
Not at allDefinitely              
   12345  

     
About Us | Advertise on This Site | User Agreement | Privacy Policy | Help
Copyright  © 2008 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a trademark of About, Inc. All rights reserved.