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 2015-02-11 08:30:10

gnetz
Member
Registered: 2015-02-11
Posts: 7

DropDownListCell for entire column.

Dim x As New DropdownListCell
x.Items.Add("aaaa1")
x.Items.Add("aaaa2")
x.Items.Add("aaaa3")

Grid.CurrentWorksheet.ColumnHeaders("B").DefaultCellBody = GetType(unvell.ReoGrid.CellTypes.DropdownListCell())

Grid.CurrentWorksheet.SetCellData("B", x)


DropDownListCell created successfully, but DropDownListCell Items not added to all the rows.

Offline

#2 2015-02-11 09:29:09

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

Re: DropDownListCell for entire column.

How many rows on your worksheet?

Last edited by Jingwood (2015-02-11 09:29:31)

Offline

#3 2015-02-11 09:32:55

gnetz
Member
Registered: 2015-02-11
Posts: 7

Re: DropDownListCell for entire column.

5000 rows sir,

Offline

#4 2015-02-11 14:02:56

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

Re: DropDownListCell for entire column.

OK since the default built-in DropdownListCell will create one ListBox instance for one cell, it will be many ListBox control instances in memory if you have so many rows. Below is a solution that the ColumnDropdownListCell class only create one ListBox control instance in memory and it will be commonly used for all cells on entire column.

Class ColumnDropdownListCell: (VB.NET)

Class ColumnDropdownListCell
	Inherits DropdownCell

	' Create only one listbox instance that is commonly used for entire column
	Shared listbox As New ListBox With {
		.BorderStyle = Windows.Forms.BorderStyle.None
	}

	Shared Sub New()
		' Initialize listbox items
		listbox.Items.AddRange({"A", "B", "C"})
	End Sub

	Sub New()
		' When cell body instance created, set listbox as dropdown control
		MyBase.DropdownControl = listbox
	End Sub

	Public Overrides Sub PushDown()
		' Add event listener when got focus
		AddHandler listbox.Click, AddressOf ListBox_Click
		MyBase.PushDown()
	End Sub

	Sub ListBox_Click(s As Object, e As EventArgs)
		' Choose listbox item, set to cell as data
		MyBase.Cell.Data = listbox.SelectedItem

		' Remove event listener when lost focus
		RemoveHandler listbox.Click, AddressOf ListBox_Click

		' Close dropdown panel
		MyBase.PullUp()
	End Sub

End Class

Use it:

' Set default body type
Me.worksheet.ColumnHeaders("B").DefaultCellBody = GetType(ColumnDropdownListCell)

' Initialize dummy data
Me.worksheet("B1:B9") = {"A", "B", "C", "A", "B", "C", "A", "B", "C"}

Offline

#5 2015-02-12 05:43:57

gnetz
Member
Registered: 2015-02-11
Posts: 7

Re: DropDownListCell for entire column.

Thank you sir,
It is working.....

Offline

Board footer

Powered by FluxBB