PDA

View Full Version : Grid Selected RowIndex -1 after some row



Kuro13
Feb 07, 2017, 2:55 AM
Hi,

I have a problem on using Checked Grid.
Here is my grid and a button for counting checked data.


<ext:GridPanel
runat="server"
ID="gridTest"
ClientIDMode="Static">
<Store>
<ext:Store
runat="server"
ID="storeTest">
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="name" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
<ColumnModel>
<Columns>
<ext:Column runat="server" Text="Name" DataIndex="name" Flex="1" />
</Columns>
</ColumnModel>
<SelectionModel>
<ext:CheckboxSelectionModel runat="server" Mode="Multi" />
</SelectionModel>
<TopBar>
<ext:Toolbar
runat="server">
<Items>
<ext:Button
runat="server"
ID="BtnCheck"
Text="Check">
<DirectEvents>
<Click OnEvent="BtnCheck_Click" />
</DirectEvents>
</ext:Button>
</Items>
</ext:Toolbar>
</TopBar>
</ext:GridPanel>


I fill the grid with 100 data with this code in Page Load event.


If Not Ext.Net.X.IsAjaxRequest Then
Dim testData As New List(Of Object())

For i As Integer = 1 To 100
testData.Add(New Object() {"Test Data " & i})
Next

storeTest.DataSource = testData.ToArray()
storeTest.DataBind()
End If


As I mention before, I have a button to counting Checked data.
Here is my code to count the checked data.


Protected Sub BtnCheck_Click(sender As Object, e As DirectEventArgs)
Dim sm As RowSelectionModel = gridTest.GetSelectionModel()

Dim counter As Integer = 0
Dim counterAll As Integer = 0
For Each selected As SelectedRow In sm.SelectedRows
If selected.RowIndex >= 0 Then
counter = counter + 1
End If

counterAll = counterAll + 1
Next

Ext.Net.X.Msg.Alert("Total Selected", counter & " Check Counted, " & counterAll & " All Checked").Show()
End Sub


The problem is, when checked all, even though the data is 100, counterAll is equal to 100 but counter is equal to 53 (maybe different). The Rest of the selected data is not counted because selected.RowIndex equal to -1.
But this only happen when check all using CTRL+A or check checkbox beside header column. When checking one by one, it works perfectly.

24837

Any idea why this is happen?