Can't access Cell data in DataGridView VB.Net
I've got a project in Visual Studio 2017, using VB.NET that populates a DataGridView using a DataTable. The data appears fine in the grid, but when I try to access the cell value in the SelectionChanged event, I always get Nothing. Here's the event:
Private Sub grdBooks_SelectionChanged(sender As Object, e As EventArgs) Handles grdBooks.SelectionChanged
If Not grdBooks.CurrentRow Is Nothing Then
If grdBooks.CurrentRow.Index > -1 Then
Dim X As String = grdBooks.Rows(0).Cells(0).Value
Dim Y = grdBooks(0, 0).Value
UpdateEditPanel(False)
End If
End If
End Sub
So both X and Y should give me the same value from the grid at position 0,0 but they don't. I've used this before in other projects. Does anybody have any ideas?
Thanks, Colin
vb.net datagridview cell
add a comment |
I've got a project in Visual Studio 2017, using VB.NET that populates a DataGridView using a DataTable. The data appears fine in the grid, but when I try to access the cell value in the SelectionChanged event, I always get Nothing. Here's the event:
Private Sub grdBooks_SelectionChanged(sender As Object, e As EventArgs) Handles grdBooks.SelectionChanged
If Not grdBooks.CurrentRow Is Nothing Then
If grdBooks.CurrentRow.Index > -1 Then
Dim X As String = grdBooks.Rows(0).Cells(0).Value
Dim Y = grdBooks(0, 0).Value
UpdateEditPanel(False)
End If
End If
End Sub
So both X and Y should give me the same value from the grid at position 0,0 but they don't. I've used this before in other projects. Does anybody have any ideas?
Thanks, Colin
vb.net datagridview cell
Did you by chance add aDataGridviewColumn
with (Visible=False
) to theDataGridview
prior to binding theDataTable
? Possibly via the designer. Try addingDataGridView1.Columns.Clear()
before setting theDataSource
.
– TnTinMn
Nov 28 '18 at 18:35
1
You have a confusing post. You say the cell is always nothing, but then you say x and y should be the same value but aren't. Which issue is it? The code you posted does not support either issue.
– LarsTech
Nov 28 '18 at 19:48
The code sample you provided works for me. I see the value in cell 0/0 when I select different items in the grid.
– ThePeter
Nov 28 '18 at 22:00
add a comment |
I've got a project in Visual Studio 2017, using VB.NET that populates a DataGridView using a DataTable. The data appears fine in the grid, but when I try to access the cell value in the SelectionChanged event, I always get Nothing. Here's the event:
Private Sub grdBooks_SelectionChanged(sender As Object, e As EventArgs) Handles grdBooks.SelectionChanged
If Not grdBooks.CurrentRow Is Nothing Then
If grdBooks.CurrentRow.Index > -1 Then
Dim X As String = grdBooks.Rows(0).Cells(0).Value
Dim Y = grdBooks(0, 0).Value
UpdateEditPanel(False)
End If
End If
End Sub
So both X and Y should give me the same value from the grid at position 0,0 but they don't. I've used this before in other projects. Does anybody have any ideas?
Thanks, Colin
vb.net datagridview cell
I've got a project in Visual Studio 2017, using VB.NET that populates a DataGridView using a DataTable. The data appears fine in the grid, but when I try to access the cell value in the SelectionChanged event, I always get Nothing. Here's the event:
Private Sub grdBooks_SelectionChanged(sender As Object, e As EventArgs) Handles grdBooks.SelectionChanged
If Not grdBooks.CurrentRow Is Nothing Then
If grdBooks.CurrentRow.Index > -1 Then
Dim X As String = grdBooks.Rows(0).Cells(0).Value
Dim Y = grdBooks(0, 0).Value
UpdateEditPanel(False)
End If
End If
End Sub
So both X and Y should give me the same value from the grid at position 0,0 but they don't. I've used this before in other projects. Does anybody have any ideas?
Thanks, Colin
vb.net datagridview cell
vb.net datagridview cell
asked Nov 28 '18 at 18:05
colinmeekscolinmeeks
12
12
Did you by chance add aDataGridviewColumn
with (Visible=False
) to theDataGridview
prior to binding theDataTable
? Possibly via the designer. Try addingDataGridView1.Columns.Clear()
before setting theDataSource
.
– TnTinMn
Nov 28 '18 at 18:35
1
You have a confusing post. You say the cell is always nothing, but then you say x and y should be the same value but aren't. Which issue is it? The code you posted does not support either issue.
– LarsTech
Nov 28 '18 at 19:48
The code sample you provided works for me. I see the value in cell 0/0 when I select different items in the grid.
– ThePeter
Nov 28 '18 at 22:00
add a comment |
Did you by chance add aDataGridviewColumn
with (Visible=False
) to theDataGridview
prior to binding theDataTable
? Possibly via the designer. Try addingDataGridView1.Columns.Clear()
before setting theDataSource
.
– TnTinMn
Nov 28 '18 at 18:35
1
You have a confusing post. You say the cell is always nothing, but then you say x and y should be the same value but aren't. Which issue is it? The code you posted does not support either issue.
– LarsTech
Nov 28 '18 at 19:48
The code sample you provided works for me. I see the value in cell 0/0 when I select different items in the grid.
– ThePeter
Nov 28 '18 at 22:00
Did you by chance add a
DataGridviewColumn
with (Visible=False
) to the DataGridview
prior to binding the DataTable
? Possibly via the designer. Try adding DataGridView1.Columns.Clear()
before setting the DataSource
.– TnTinMn
Nov 28 '18 at 18:35
Did you by chance add a
DataGridviewColumn
with (Visible=False
) to the DataGridview
prior to binding the DataTable
? Possibly via the designer. Try adding DataGridView1.Columns.Clear()
before setting the DataSource
.– TnTinMn
Nov 28 '18 at 18:35
1
1
You have a confusing post. You say the cell is always nothing, but then you say x and y should be the same value but aren't. Which issue is it? The code you posted does not support either issue.
– LarsTech
Nov 28 '18 at 19:48
You have a confusing post. You say the cell is always nothing, but then you say x and y should be the same value but aren't. Which issue is it? The code you posted does not support either issue.
– LarsTech
Nov 28 '18 at 19:48
The code sample you provided works for me. I see the value in cell 0/0 when I select different items in the grid.
– ThePeter
Nov 28 '18 at 22:00
The code sample you provided works for me. I see the value in cell 0/0 when I select different items in the grid.
– ThePeter
Nov 28 '18 at 22:00
add a comment |
2 Answers
2
active
oldest
votes
I am a bit confused by this post aswell but I hope this helps you resolve the problem. Possible solution #1
Dim X As String = DataGridView1.SelectedRows(0).Cells(0).Value.ToString
or
Dim X As String = DataGridView1.SelectedRows(0).Cells(0).Value.ToString()
If you are able to provide more code, I'm sure we can resolve this Issue. Cheers.
add a comment |
If you just want to click the cell from the Grid, try this:
Private Sub grdBooks_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles grdBooks.CellContentClick
Dim selectedRow As DataGridViewRow
selectedRow = grdBooks.Rows(e.RowIndex)
Dim x as string = selectedRow.Cells(0).Value.ToString()
End Sub
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53525532%2fcant-access-cell-data-in-datagridview-vb-net%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
I am a bit confused by this post aswell but I hope this helps you resolve the problem. Possible solution #1
Dim X As String = DataGridView1.SelectedRows(0).Cells(0).Value.ToString
or
Dim X As String = DataGridView1.SelectedRows(0).Cells(0).Value.ToString()
If you are able to provide more code, I'm sure we can resolve this Issue. Cheers.
add a comment |
I am a bit confused by this post aswell but I hope this helps you resolve the problem. Possible solution #1
Dim X As String = DataGridView1.SelectedRows(0).Cells(0).Value.ToString
or
Dim X As String = DataGridView1.SelectedRows(0).Cells(0).Value.ToString()
If you are able to provide more code, I'm sure we can resolve this Issue. Cheers.
add a comment |
I am a bit confused by this post aswell but I hope this helps you resolve the problem. Possible solution #1
Dim X As String = DataGridView1.SelectedRows(0).Cells(0).Value.ToString
or
Dim X As String = DataGridView1.SelectedRows(0).Cells(0).Value.ToString()
If you are able to provide more code, I'm sure we can resolve this Issue. Cheers.
I am a bit confused by this post aswell but I hope this helps you resolve the problem. Possible solution #1
Dim X As String = DataGridView1.SelectedRows(0).Cells(0).Value.ToString
or
Dim X As String = DataGridView1.SelectedRows(0).Cells(0).Value.ToString()
If you are able to provide more code, I'm sure we can resolve this Issue. Cheers.
answered Nov 28 '18 at 22:10
DJNDJN
366
366
add a comment |
add a comment |
If you just want to click the cell from the Grid, try this:
Private Sub grdBooks_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles grdBooks.CellContentClick
Dim selectedRow As DataGridViewRow
selectedRow = grdBooks.Rows(e.RowIndex)
Dim x as string = selectedRow.Cells(0).Value.ToString()
End Sub
add a comment |
If you just want to click the cell from the Grid, try this:
Private Sub grdBooks_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles grdBooks.CellContentClick
Dim selectedRow As DataGridViewRow
selectedRow = grdBooks.Rows(e.RowIndex)
Dim x as string = selectedRow.Cells(0).Value.ToString()
End Sub
add a comment |
If you just want to click the cell from the Grid, try this:
Private Sub grdBooks_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles grdBooks.CellContentClick
Dim selectedRow As DataGridViewRow
selectedRow = grdBooks.Rows(e.RowIndex)
Dim x as string = selectedRow.Cells(0).Value.ToString()
End Sub
If you just want to click the cell from the Grid, try this:
Private Sub grdBooks_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles grdBooks.CellContentClick
Dim selectedRow As DataGridViewRow
selectedRow = grdBooks.Rows(e.RowIndex)
Dim x as string = selectedRow.Cells(0).Value.ToString()
End Sub
answered Nov 29 '18 at 3:36
PratilectronPratilectron
11
11
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53525532%2fcant-access-cell-data-in-datagridview-vb-net%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Did you by chance add a
DataGridviewColumn
with (Visible=False
) to theDataGridview
prior to binding theDataTable
? Possibly via the designer. Try addingDataGridView1.Columns.Clear()
before setting theDataSource
.– TnTinMn
Nov 28 '18 at 18:35
1
You have a confusing post. You say the cell is always nothing, but then you say x and y should be the same value but aren't. Which issue is it? The code you posted does not support either issue.
– LarsTech
Nov 28 '18 at 19:48
The code sample you provided works for me. I see the value in cell 0/0 when I select different items in the grid.
– ThePeter
Nov 28 '18 at 22:00