ReoGrid Forum

Fast and powerful .NET Spreadsheet Component

You are not logged in.

Announcement

This forum has been archived and no longer accepts new user registrations. Please report your questions, problems, and feedback to the issue page of ReoGrid on GitHub. Thank you for your cooperation.

https://github.com/unvell/ReoGrid/issues

#1 2016-03-21 07:00:47

asparatu
Member
Registered: 2014-08-20
Posts: 196

How to get selectedindex of cell?

Hello Jing,
   If have a cell as dropdownlistcell, I want to know i can reference selectedindex in code? I see from the example you need to new variable.

var dropdown = new DropdownListCell(
  "Apple", "Orange", "Banana", "Pear", 
  "Pumpkin", "Cherry", "Coconut"
);
sheet["B2"] = dropdown;

if do dropdown.selectedindex it will tell my what is the index but.. if have same dropdown variable for 10 columns how do know which one i will use?

how can check cell B2 and see what the selectedindex is?

This how i am doing in code

sheet.SetCellData(3, col, New SigmaAid.Controls.DropdownListCell(My.Resources.strLowTitle, My.Resources.strHighTitle, My.Resources.strCloseToTarget))

I want to know if can do something like this i see i can get the index value using the SelectedItemChanged Event, but i dont always want to get that way.

  dim idx as int32
  
  idx = sheet.cells("B2").selectedindex (do something like that?)

After testing i see can not use the same variable for every cell but need to make new one for each cell.

Shane

Offline

#2 2016-03-21 07:03:29

Jingwood
Moderator
From: jing at reogrid.net
Registered: 2014-06-03
Posts: 615

Re: How to get selectedindex of cell?

The built-in drop-down list requires that one instance for one cell. You can make your own drop-down list cell for multiple cell.

When using the built-in one, the sender of SelectedIndexChanged event is the drop-down list instance, it's property Cell is the cell of drop-down selected.

The below code makes ten drop-down cells inside ten cells and finds the source cell when drop-down is selected.

VB.NET:

Imports unvell.ReoGrid.CellTypes

Public Class Form5

  Private Sub Form5_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Dim sheet = grid.CurrentWorksheet

    For i As Integer = 0 To 10
      Dim dropdown = New DropdownListCell("Apple", "Orange", "Banana",
	                                  "Pear", "Pumpkin", "Cherry", "Coconut")

      AddHandler dropdown.SelectedItemChanged, AddressOf Dropdown_SelectedIndexChanged

      sheet(0, i) = dropdown
    Next
  End Sub

  Sub Dropdown_SelectedIndexChanged(sender As Object, e As EventArgs)
    Dim dropdown = DirectCast(sender, DropdownListCell)
    MsgBox(dropdown.Cell.Address)
  End Sub

End Class

Last edited by Jingwood (2016-03-21 07:08:09)

Offline

#3 2016-03-21 07:39:39

asparatu
Member
Registered: 2014-08-20
Posts: 196

Re: How to get selectedindex of cell?

Hello Jing,
    I think if would be good idea. if you have built-in controls or even Inherited built-in controls that you get values easier.. You have so get the cell address of the cell but might want to something like this for dropdownlistcell and checkbox and radios, have control.cells(address).SelectedIndex or SelectedItem and control.cells(Address).isChecked, so you check the data outside of the event.

I was think how to Get and Set the values?

I see that i have make a table that will hold the information for the index values. unless there access the index value of the a cell without using the event?

Shane

Last edited by asparatu (2016-03-21 08:23:37)

Offline

#4 2016-03-21 09:07:08

asparatu
Member
Registered: 2014-08-20
Posts: 196

Re: How to get selectedindex of cell?

Hello Jing,
   I found away around to do what i need to do. I am just going to make generic list of dropdownlistcell and get the data that way. If there is easier way please tell me.
Shane

Offline

#5 2016-03-21 14:07:37

asparatu
Member
Registered: 2014-08-20
Posts: 196

Re: How to get selectedindex of cell?

Hello Jing,
   I tried to do what i said but didnt work. I was not able to set the selectedindex  because the object was null. I know it was created and i can see it in the list..

Shane

Offline

Board footer

Powered by FluxBB