DataGrid Current Row and Field
-
How do I get the contents of the current field and row from a datagrid? I have set up the code to run when I click on a record in the datagrid and this works until you sort the datagrid by clicking on the column headers. dim test as string test = TestGrid.CurrentRowIndex COMPANY.Text = CODE_DataSet.Tables(CODE_TABLE).Rows(test).Item(0) Any Idesas? :confused:
-
How do I get the contents of the current field and row from a datagrid? I have set up the code to run when I click on a record in the datagrid and this works until you sort the datagrid by clicking on the column headers. dim test as string test = TestGrid.CurrentRowIndex COMPANY.Text = CODE_DataSet.Tables(CODE_TABLE).Rows(test).Item(0) Any Idesas? :confused:
What's happening is the currency manager for the datagrid is no longer pointing to the correct row after you perform a sort. Here's a good description of the problem and a potential solution: http://weblogs.asp.net/dmarsh/archive/2003/01/22/646.aspx[^]
-
How do I get the contents of the current field and row from a datagrid? I have set up the code to run when I click on a record in the datagrid and this works until you sort the datagrid by clicking on the column headers. dim test as string test = TestGrid.CurrentRowIndex COMPANY.Text = CODE_DataSet.Tables(CODE_TABLE).Rows(test).Item(0) Any Idesas? :confused:
There is an ItemCommand event that fires when you click something in the datagrid one of the arguments for that event is DataGridCommandEventArgs let's call it "e" myItemCommand (object sender, DataGridCommandEventArgs e ) { e.Item.DataItem[0]; /*This a DataRowViewRow*/ } That is how you access a row in a datagrid. Please let me know if I missunderstood your question or there's anything else I can help you with. Greetings, Felipe
-
There is an ItemCommand event that fires when you click something in the datagrid one of the arguments for that event is DataGridCommandEventArgs let's call it "e" myItemCommand (object sender, DataGridCommandEventArgs e ) { e.Item.DataItem[0]; /*This a DataRowViewRow*/ } That is how you access a row in a datagrid. Please let me know if I missunderstood your question or there's anything else I can help you with. Greetings, Felipe
OK I think I have got what I am looking for with: Dim MyCell As DataGridCell Dim MyRow As Integer Dim MyCol As Integer Dim MyData As String MyCell = TestGrid.CurrentCell MyRow = (MyCell.RowNumber) MyCol = (MyCell.ColumnNumber) MyData = CODE_DataSet.Tables(CODE_TABLE).Rows(MyRow).Item(MyCol) COMPANY.Text =MyData This will work as long as there is data in the cell I clicked on. How do I test for NULL? What variable type do I need to set MyData so I dont get a compiler error "Cast from type DBNull to type String in not valid"
-
OK I think I have got what I am looking for with: Dim MyCell As DataGridCell Dim MyRow As Integer Dim MyCol As Integer Dim MyData As String MyCell = TestGrid.CurrentCell MyRow = (MyCell.RowNumber) MyCol = (MyCell.ColumnNumber) MyData = CODE_DataSet.Tables(CODE_TABLE).Rows(MyRow).Item(MyCol) COMPANY.Text =MyData This will work as long as there is data in the cell I clicked on. How do I test for NULL? What variable type do I need to set MyData so I dont get a compiler error "Cast from type DBNull to type String in not valid"
IF IsDBNull(MyData) Then COMPANY.Text="" Else COMPANY.Text=MyData End IF !alien!