Can't set value of datagridview cell

G

Guest

I'm going to bother you on one more question. Tell me if I'm out of line.
This one ha 441 views without an answer.

I might mention that these datagridviews are totally unbound. The column
headers I created in the column collection.

Can't set value of datagridview cell

The documentation claims you can set the cell value thusly:

Private Sub SetCellValue(ByVal myGrid As DataGrid)
Dim myCell As New DataGridCell()
' Use an arbitrary cell.
myCell.RowNumber = 1
myCell.ColumnNumber = 1
' Change the cell's value using the CurrentCell.
myGrid(myCell)= "New Value"
End Sub

MsgBox("new row index " & Me.DataGridView1.NewRowIndex.ToString)
MsgBox("rowcount " & Me.DataGridView1.RowCount.ToString())
gives me the respective messages 0 and 1 respectively. I might add that the
datagridview is unbound and without a datasource.

Dim aCell As New DataGridView1cell gives me the message
datagridview1cell is not defined.

Further in the documentation are examples. I adapted the examples

Dim rowArray As String()


'Dim row1() As String = {"Meatloaf", "Main Dish", "ground beef", "**"}
to
Dim row1 As String = {Me.WATopicID.ToString(), Me.KeywordSetTextBox.Text, "?"}

The questionmark is because the example is for all columns as textboxes.
Nowhere did I find documentation on how to fill a row with other controls as
columns, particularly a checkbox.

Dim rowArray As String()
For Each rowArray In rows
dataGridView1.Rows.Add(rowArray)
Next rowArray

However, rows is undeclared. It seems the documentation is behind the
current implementation of the beta framework.

Can somebody help me?

You might ask why I don't add a datasource for the keywords grid? Because I
have thousands of keywords. It's easier to just execute an insertquery to
the tableadapter and not have to drain a large amount of resources and slow
the user experience considerably.

dennist685
 
È

ÈÎÔ¶[΢Èí]

Hi Dennist,

Welcome for MSDN newsgroup!

For current issue, the DataGridViewCell class is a MustInherit class in
NET Framework beta v2.0, so we can not create a new instance for it
directly. The following document gives us more detail information about it:
http://msdn2.microsoft.com/library/h6eeb94b(en-us,vs.80).aspx

Based on my understanding, you want to add a checkbox control into the
current DataGridView, please notify me if I make a misunderstanding. I
suggest we use the below fragment code to add a column checkbox:
Dim column As DataGridViewColumn = New DataGridViewCheckBoxColumn()
column.DataPropertyName = "GoodGuy"
column.Name = "Good"
dataGridView1.Columns.Add(column)

I hope the suggestions were helpful. If you have any other concerns, please
feel free to let me know.. It's my pleasure to be of assistance.

Yuan Ren[MSFT]
 
G

Guest

Yuan,

So far so good. However how to I associate the datagridviewcolumn with
datagridview1 in particular. I can see how I can create my three columns,
but I don't see how I can apply them to a particular datagridview.

I hope I'm explaining myself clearly. You were.

The second question is putting the values in row0. would they be
Dim row1 As String = {Me.WATopicID.ToString(),
Me.KeywordSetTextBox.Text,
checked}

Thanks for spending time solving my problems.

dennist685
 
K

Kevin Yu [MSFT]

Hi Dennis,

To specify the column data that is displaying, you can use the
DataPropertyName property. Please check the following link for more
information.

http://msdn2.microsoft.com/library/584edt5s(en-us,vs.80).aspx

What do you mean by setting values in row0, if you need to set value for a
certain column, please use row0("columnname") = value

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 

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