• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 460
  • Last Modified:

This question is specific to the XPTable control

I need to know how to programmatically pull the value of the first column of a selection made with this control.

The control in question is located here:


I just simply need to know how to get the first row value of any row selected.
John Gates, CISSP
John Gates, CISSP
  • 7
  • 5
1 Solution
Looking at the sample code on the website:

The TableModel also provides a Selection object that you can use to programmatically select or deselect Cells.

Is that any help?
John Gates, CISSPSecurity ProfessionalAuthor Commented:
No what I can't figure out is the following:

I have populated the control with data there are 7 columns of data for each row.  Now the user clicks the row.  In that event I want to get the value of column 0 lets say on the selected row.  I cannot seem to achieve this.  If you know how can you post a code sample to do so?

Thanks in advance,
John Gates, CISSPSecurity ProfessionalAuthor Commented:
Ok I have figured out one way to do it... Please someone out there tell me it does not have to be this way:

 Dim h As Object
        Dim i As Integer
        Dim j As String
        Dim k As String

        h = TableModel1.Rows.Count.ToString

        For i = 0 To h - 1

            'MsgBox("iterate the row")
            j = TableModel1.Rows(i).AnyCellsSelected.ToString

            If j = "True" Then


                k = TableModel1.Item(i, 0).Text().ToString()

            End If


When I use this code on the click event I get the desired value...  My question is why do I have to go through each record in the control?  Am I missing something?


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

You can add a handler to
I did it in C#
but you just need to add a handler to

this.table.TableModel.SelectionChanged +=new XPTable.Events.SelectionEventHandler(TableModel_SelectionChanged);

private void TableModel_SelectionChanged(object sender, XPTable.Events.SelectionEventArgs e)
In VB it will be like

Addhandler TableModel1.SelectionChanged, Addressof TableModel_SelectionChanged

and then your handler:

Private sub TableModel_SelectionChanged (sender as object, e as XPTable.Events.SelectionEventsArgs)
'your selection is inside 'e'
'e.newSelectedIndicies contains your selection
end sub
John Gates, CISSPSecurity ProfessionalAuthor Commented:
Can you elaborate in VB.NET? with the handler code..  Is my code above close to what needs to be there?

Well, like I said in my last message,
you could take the SelectionChanged event OR you could:

private sub ShowSelection()

for each row as XPTable.Models.Row in table.TableModel.Selections.SelectedItems
'show the item in your first column
  MessageBox.Show (row.Cells(0).Text)

probably in your case you replace table.TableModel by TabelModel1
John Gates, CISSPSecurity ProfessionalAuthor Commented:
Where would this line go?

Addhandler TableModel1.SelectionChanged, Addressof TableModel1_SelectionChanged

I get a syntax error anywhere I try to put that on the code page..

This line
Gives the error selections not a member of xptable...  So that snippet does not work either...

I am really frustrated with this..  So I have posted this in the VB.NET area.  Please post a working example in VB.NET and the points are yours.
John Gates, CISSPSecurity ProfessionalAuthor Commented:
I finally figured it out...  In the future you should post vb.net solutions in the vb.net thread not C#..
Uhm, I posted VB.NET code as well, didnt i? And where did I type table.selections?
I typed tableModel didnt I?
John Gates, CISSPSecurity ProfessionalAuthor Commented:
The answer I accepted was in VB correct.
Well, the sample on the website you posted was in c#..
So not very strange to assume you could read c# as well?
John Gates, CISSPSecurity ProfessionalAuthor Commented:
Why are you turning this into a debate?  I wanted a VB.net answer does not matter what the control is programmed in..  I hate C# for one simple reason...  It looks just too much like Java, period.  I can read it and convert it but why have to take the extra steps?

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 7
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now