EDN Admin
Well-known member
1. I have a DataGridView control that displays data using the BindingSource control.
2. Inside the DataGridView I have a DataGridViewComboBoxColumn control that displays a different set of relational data using the BindingSource control. The DisplayMember property is set to "Expense" and the ValueMember property is set to
"ExpenseID".
3. The DataSource for both BindingSource controls is a DataSet of type .xsd
I need to get the values of four cells in the current row during the RowLeave event and I am able to grab three of the four values using:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; Dim month <span style="color:Blue; As <span style="color:Blue; Integer = DataGridView1.CurrentRow.Cells(3).Value
<span style="color:Blue; Dim amountID <span style="color:Blue; As <span style="color:Blue; Integer = DataGridView1.CurrentRow.Cells(2).Value
<span style="color:Blue; Dim amount <span style="color:Blue; As <span style="color:Blue; Decimal = DataGridView1.CurrentRow.Cells(1).Value
[/code]
I need to get the current ValueMember from the DataGridViewComboBoxColumn in Cell(0). So first I tried:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; Dim expenseID1 <span style="color:Blue; As <span style="color:Blue; Integer = DataGridView1.CurrentRow.Cells(0).Value
[/code]
Then I tried:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; Dim expenseID2 <span style="color:Blue; As <span style="color:Blue; Integer = DataGridView1(0, e.RowIndex).Value
[/code]
Both lines of code return the DisplayMember property.
Ive been to different forums and MSDN walkthroughs that show how to do it when you are binding data programmatically. I tried them all but they all seem not to work for getting the CurrentRow ValueMember.
How do I get the CurrentRows DataGridViewComboBoxColumn.ValueMember?
Full Code:
The Code crashes on ExpenseId because is of type integer and the currentrow returns the DisplayMember which is of type string. I am expecting an Integer from the ValueMember which I do not know how to get.
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; Private <span style="color:Blue; Sub DataGridView1_RowLeave(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.Windows.Forms.DataGridViewCellEventArgs) <span style="color:Blue; Handles DataGridView1.RowLeave
<span style="color:Blue; Dim cbDataGridColumn <span style="color:Blue; As DataGridViewComboBoxColumn = ExpenseDataGridViewTextBoxColumn
<span style="color:Blue; Try
<span style="color:Blue; Dim month <span style="color:Blue; As <span style="color:Blue; Integer = DataGridView1.CurrentRow.Cells(3).Value
<span style="color:Blue; Dim amountID <span style="color:Blue; As <span style="color:Blue; Integer = DataGridView1.CurrentRow.Cells(2).Value
<span style="color:Blue; Dim amount <span style="color:Blue; As <span style="color:Blue; Decimal = DataGridView1.CurrentRow.Cells(1).Value
<span style="color:Blue; Dim expenseID <span style="color:Blue; As <span style="color:Blue; Integer = DataGridView1.CurrentRow.Cells(0).Value
<span style="color:Blue; Catch ex <span style="color:Blue; As Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
<span style="color:Blue; End <span style="color:Blue; Try
<span style="color:Blue; End <span style="color:Blue; Sub
[/code]
<br/>
<br/>
View the full article
2. Inside the DataGridView I have a DataGridViewComboBoxColumn control that displays a different set of relational data using the BindingSource control. The DisplayMember property is set to "Expense" and the ValueMember property is set to
"ExpenseID".
3. The DataSource for both BindingSource controls is a DataSet of type .xsd
I need to get the values of four cells in the current row during the RowLeave event and I am able to grab three of the four values using:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; Dim month <span style="color:Blue; As <span style="color:Blue; Integer = DataGridView1.CurrentRow.Cells(3).Value
<span style="color:Blue; Dim amountID <span style="color:Blue; As <span style="color:Blue; Integer = DataGridView1.CurrentRow.Cells(2).Value
<span style="color:Blue; Dim amount <span style="color:Blue; As <span style="color:Blue; Decimal = DataGridView1.CurrentRow.Cells(1).Value
[/code]
I need to get the current ValueMember from the DataGridViewComboBoxColumn in Cell(0). So first I tried:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; Dim expenseID1 <span style="color:Blue; As <span style="color:Blue; Integer = DataGridView1.CurrentRow.Cells(0).Value
[/code]
Then I tried:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; Dim expenseID2 <span style="color:Blue; As <span style="color:Blue; Integer = DataGridView1(0, e.RowIndex).Value
[/code]
Both lines of code return the DisplayMember property.
Ive been to different forums and MSDN walkthroughs that show how to do it when you are binding data programmatically. I tried them all but they all seem not to work for getting the CurrentRow ValueMember.
How do I get the CurrentRows DataGridViewComboBoxColumn.ValueMember?
Full Code:
The Code crashes on ExpenseId because is of type integer and the currentrow returns the DisplayMember which is of type string. I am expecting an Integer from the ValueMember which I do not know how to get.
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; Private <span style="color:Blue; Sub DataGridView1_RowLeave(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.Windows.Forms.DataGridViewCellEventArgs) <span style="color:Blue; Handles DataGridView1.RowLeave
<span style="color:Blue; Dim cbDataGridColumn <span style="color:Blue; As DataGridViewComboBoxColumn = ExpenseDataGridViewTextBoxColumn
<span style="color:Blue; Try
<span style="color:Blue; Dim month <span style="color:Blue; As <span style="color:Blue; Integer = DataGridView1.CurrentRow.Cells(3).Value
<span style="color:Blue; Dim amountID <span style="color:Blue; As <span style="color:Blue; Integer = DataGridView1.CurrentRow.Cells(2).Value
<span style="color:Blue; Dim amount <span style="color:Blue; As <span style="color:Blue; Decimal = DataGridView1.CurrentRow.Cells(1).Value
<span style="color:Blue; Dim expenseID <span style="color:Blue; As <span style="color:Blue; Integer = DataGridView1.CurrentRow.Cells(0).Value
<span style="color:Blue; Catch ex <span style="color:Blue; As Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
<span style="color:Blue; End <span style="color:Blue; Try
<span style="color:Blue; End <span style="color:Blue; Sub
[/code]
<br/>
<br/>
View the full article