Results 1 to 1 of 1

Thread: Calling Individual GridView cells and updating them, doing it cleanly.. How do I?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2007
    Posts
    28

    Calling Individual GridView cells and updating them, doing it cleanly.. How do I?

    What I am trying to do is create some sort of special event that if a certain value in a drop down menu bar that I created is selected and executed than a dataGridView is updated. I realize that I could just put function calls in the code of the menu items so that Gridview is updated. I feel intuitively however that this way is probably very inefficient and I am trying to understand the correct way to do it. How I am doing it now is dynamically so I start by declaring rows:

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    DataGridView1.ColumnCount = 3
    DataGridView1.Columns(0).Name = "FirstName"
    DataGridView1.Columns(1).Name = "LastName"
    DataGridView1.Columns(2).Name = "Color"
    PopulateGridView()
    End Sub

    And create a subroutine that puts stuff into the DataGridView:

    Public Sub PopulateGridView()
    Dim row1 As String() = New String() _
    {"Something for Row 1 Column 1", "Something for Row 1 Column 2", Convert.ToString(My.Settings.UserControl1_BackColor)}

    Dim row2 As String() = New String() _
    {"Something for Row 2 Column 1", "Something for Row 2 Column 2", Convert.ToString(My.Settings.UserControl2_BackColor)}
    Dim row3 As String() = New String() _
    {"Something for Row 3 Column 1", "Something for Row 3 Column 2", Convert.ToString(My.Settings.UserControl3_BackColor)}

    Dim rows As Object() = New Object() {row1, row2, row3}

    Dim rowArray As String()
    For Each rowArray In rows

    DataGridView1.Rows.Add(rowArray)
    Next

    End Sub

    I however don’t really need to do it dynamically but when I was trying to figure things out, the tutorials that I dug up that did it this way actually made sense. That’s the first thing, is there a better, more efficient way to do this so that everytime one value changes in which aspecific cell needs to be updated the program does not have go through all the updating of the row(i) arrays and then sticking them into DataGridView? Should I use DataGridView1.UpdateCellValue(y,x) of some sorts? The problem that I forsee here is that if one property of one child instance of this class I built is updated then I will have to write a DataGridView1.UpdateCellValue(y,x) for each possible property change in each instance of the child on the form. I however think that I should be able to somehow ingrain this into the actual class so that if any of the instances are changed, then the event will be handled through the parent. I think that might be the right track, (but I am not sure). If it is however, I don’t know how to do it. I am having a problem being able to call this DataGridView1.UpdateCellValue(y, x) method from another class which is in a different project which is part of the same solution. I however have made a little example of my problem… It is attached and I would very much appreciate it if someone could take a look at it. It has a UserControl Class in one project and a form in the other which has the DataGridView on it. I want to be able to contact this DataGridView object through the code of the UserClass but I don’t know how. This ofcourse is only if this is an efficient way to do this and I wonder if somehow I should try to make the DataGridView static, but I am not quite sure how. On top of that, if it is static, I will still have to update the cells on change.

    Anyways, sorry for writing a book here, but I am really trying to make sense of what I am trying to do.

    Thanks much,

    Brian
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width