Desktop Grid - GridColumn.AddComboBox

Hi

I am using Desktop Grid. I am importing a datatable in a grid and then trying to a combobox in the one of columns with the help of following code. But it’s not showing any Combobox in the specified column.
Could you please tell me, what could be the issue?

Code:
grdDataEntry.Worksheets(0).ImportDataTable(ldtAllData, True, 0, 0)
Dim InvestorCol As GridColumn
InvestorCol = sheet.Columns(1))
Dim ldtInvestors As New DataTable
ldtInvestors = LoadInvestors() 'It returns a datatable
InvestorCol.AddComboBox(ldtInvestors.Rows)

Hi,

Thank you for considering Aspose.

Well, I have tested your scenario by creating a datatable and it works fine. Please see the sample code which I used. Make sure ldtInvestors = LoadInvestors() loads the data table properly and you should also call ldtInvestors.AcceptChanges() to commit the changes in the datatable.
Sample Code:

Dim sheet As Aspose.Grid.Desktop.Worksheet =

Me.GridDesktop.GetActiveWorksheet()

Dim cl As CellLocation = sheet.GetFocusedCellLocation()

Dim dtable As DataTable = New DataTable()

dtable.Columns.Add("Aspose")

dtable.Columns.Add("Aspose.Grid")

dtable.Columns.Add("Aspose.Grid.Desktop")

dtable.AcceptChanges()

Dim row As DataRow = dtable.NewRow()

row(0) = "Aspose"

row(1) = "Aspose.Grid"

row(2) = "Aspose.Grid.Desktop"

dtable.Rows.Add(row)

row = dtable.NewRow()

row(0) = "Aspose"

row(1) = "Aspose.Grid"

row(2) = "Aspose.Grid.Desktop"

dtable.Rows.Add(row)

dtable.AcceptChanges()

sheet.Columns(0).AddComboBox(dtable.Rows)

One thing which I want to add is that you are assigning the DataTable.Rows as a parameter to the AddComboBox() method and it will populate the combobox with the System.Data.DataRow as values because it is a collection of Rows. You should assign some string value collection to fill your combo. Like you can use single Row values to be populated to the combo by using sheet.Columns(0).AddComboBox(dtable.Rows(0).ItemArray). This will populate your first row values to the combo box.

To Load Combo With a string Collection you may see the following Code.

Dim sheet As Aspose.Grid.Desktop.Worksheet = Me.GridDesktop.GetActiveWorksheet()

Dim cl As CellLocation = sheet.GetFocusedCellLocation()

Dim items() As String = New String(3) {}

items(0) = "Aspose"

items(1) = "Aspose.Grid"

items(2) = "Aspose.Grid.Desktop"

sheet.Controls.AddComboBox(cl.Row, cl.Column, items)

If you still have any confusion, please explain your requirement in detail, so we can provide you with an appropriate solution.

Thank You & Best Regards,

Hi

Can we have multi columns drop downs in grid column as shown in the attached screen shot?

Hi,

Well, the feature is not available currently as the ComboBox has one column only. We may consider your desired feature and will implement it out our future versions. We cannot give you an eta at the moment, we can only look into it after completing some other important tasks on hand.

Thanks for your understanding.

Hi

In Aspose.grid, ‘values’ parameter refers to the values that will be visible in the combo box. Could you please tell me what this ‘items’ parameter is for? Can you give me an example to make it clear?
Also, I have my data in a data table (not in ICollection) that I need to bind to combo box. Could you suggest me the best way for it.

public void AddComboBox(
ICollection items,
ICollection values
);

Thanks

Hi,

Thanks for your inquiry.

Well, for the overloaded version of the method i.e..,
public void AddComboBox(

int row,
int col,
ICollection items
);

where “items” means the collection of the items contained in ComboBox, If one of the item is selected, the selected item will be set to the cell.

And for the overloaded version of the method i.e..,
public void AddComboBox(
int row,
int col,
ICollection items,
ICollection values
);

where “items” means the collection of the items contained in ComboBox and “values” means the corresponding values that will be set to the cell if one of the item is selected. Please add the combo box using the code (given below) and select any item in the combo box (clicking on F3 cell), you will see the corresponding value is automatically set to the cell and shown.

And, if you need to use data of DataTable to bind to combo box, you have to extract the data to ArrayList first, like the sample code:

Sample code:

Dim gridDesktop1 As GridDesktop = Me.grdDataEntry
gridDesktop1.Worksheets.Add()
Dim sheet As Worksheet = gridDesktop1.GetActiveWorksheet()
sheet.ColumnsCount = 15
sheet.RowsCount = 15
Dim dt As New System.Data.DataTable()
Dim dr As System.Data.DataRow
dt.Columns.Add("nitem")
dt.Columns.Add("nvalue")
Dim line As Integer = 1
While (line < 5)


dr = dt.NewRow()
dr(0) = "nitem " & line
dr(1) = "nvalue " & line
line += 1
dt.Rows.Add(dr)

End While

Dim rowCount As Integer = dt.Rows.Count
Dim nitem As New ArrayList()
Dim nvalue As New ArrayList()
For i As Integer = 0 To rowCount - 1

Dim row As DataRow = dt.Rows(i)
nitem.Add(CStr(row(0)))
nvalue.Add(CStr(row(1)))

Next i

sheet.Controls.AddComboBox("F3", nitem, nvalue)

Thank you.