ASPxGridViewExporter does not export the data - vb.net

i have dev express ASPxGridView. the column and data for the gridview will be dynamically based on the dropdown value.
If type = "procedure" Then
SqlDataSource2.SelectCommandType = SqlDataSourceCommandType.StoredProcedure
Else
SqlDataSource2.SelectCommandType = SqlDataSourceCommandType.Text
End If
SqlDataSource2.SelectCommand = rptquery
Try
SqlDataSource2.DataBind()
dataview1 = SqlDataSource2.Select(System.Web.UI.DataSourceSelectArguments.Empty)
gv.DataSourceID = "SqlDataSource2"
For Each dc In dataview1.Table.Columns
Dim DynamicColumn = New DevExpress.Web.ASPxGridView.GridViewDataTextColumn()
DynamicColumn.FieldName = dc.ColumnName
DynamicColumn.Caption = dc.ColumnName
gv.Columns.Insert(i, DynamicColumn)
i = i + 1
Next
gv.DataBind()
Catch ex As Exception
End Try
Then i have export button to excel. my problem is it will only export the column name of the gridview into the excel sheey. data is empty. but in gridview data is shown.
please help me on this issue.

Make sure that you have bound ASPxGridView prior using the using the ASPxGridViewExporter.Write*** method:
'SqlDataSource2.DataBind()
'dataview1 = SqlDataSource2.Select(System.Web.UI.DataSourceSelectArguments.Empty)
ASPxGridViewExporterInstance.GridView = gv
gv.DataSource = SqlDataSource2
ASPxGridViewExporterInstance.Write***

Related

Libreoffice Unable to fill ListBox because I could not declare the listbox righteously

I have a Listbox in my Calc Worksheet and I am trying to address it for filling it with data
DialogLibraries.LoadLibrary("Standard")
oDialog = CreateUnoDialog(DialogLibraries.Standard)
listBoxGruppe = oEvent.Source.Context.getControl("Drop_Down_5") 'oDialog.getControl("Drop_Down_5")
aItems = sheetb.getCellRangeByName(subStrRan).dataarray
Dim sItems(ubound(aItems))
For i = 0 To ubound(aItems)
sItems(i) = aItems(i)(0)
Next i
listBoxGruppe.addItems(sItems, 0)
oDialog.Execute()
However, it seems u need to call a certain Dialog, but idk what is the name of my Dialog for this scenario - this is how my code behind looks like
I think you don't need dialogs at this situation
dim RangeAddr as new com.sun.star.table.CellRangeAddress
RangeAddr.EndColumn = 1
RangeAddr.EndRow = Cell.CellAddress.Row
RangeAddr.Sheet = 2
RangeAddr.StartColumn = 1
RangeAddr.StartRow = 0
dim initParam(0) as new com.sun.star.beans.NamedValue
initParam(0).Name="CellRange"
initParam(0).Value = RangeAddr
CellRangeListSource = doc.createInstanceWithArguments("com.sun.star.table.CellRangeListSource", initParam )
listBoxGruppe.setListEntrySource CellRangeListSource

Data grid view with combo box , add rows from data table

Search and display data in data grid view
Dim cmd As New OracleCommand("Select JV_CODE,JV_ACC_NAME,DEBIT,CREDIT From VOUCHER_DETAIL where VOUCHERNO =:Vno", sgcnn)
cmd.Parameters.Add("#Vno", OracleDbType.NVarchar2).Value = txtJVNo.Text.ToString.Trim
Dim daVD As New OracleDataAdapter(cmd)
Dim dtVD As New DataTable()
daVD.Fill(dtVD)
dgvAccDetail.AutoGenerateColumns = False
dgvAccDetail.DataSource = dtVD
dgvAccDetail.Rows(0).Cells(0).Value = dtVD.Rows(0).Item("JV_CODE").ToString.Trim
dgvAccDetail.Rows(0).Cells(1).Value = dtVD.Rows(0).Item("JV_ACC_NAME").ToString.Trim
dgvAccDetail.Rows(0).Cells(2).Value = dtVD.Rows(0).Item("DEBIT").ToString.Trim
dgvAccDetail.Rows(0).Cells(3).Value = dtVD.Rows(0).Item("CREDIT").ToString.Trim
Catch ex As Exception
MsgBox(ex.Message)
End Try
There are two rows in dtVD data table but result shows only one I stack with this some can tell what I'm doing wrong ?
The reason for this is that you are only assigning the one row. You have a couple options:
First, this code below here shouldn't really be necessary, of you setup the property binding on the grid. You'll get better performance that way if you use a bind. You don't have your GUI code here, but essentially your DataPropertyName field on the columns should be set.
dgvAccDetail.Rows(0).Cells(0).Value = dtVD.Rows(0).Item("JV_CODE").ToString.Trim
dgvAccDetail.Rows(0).Cells(1).Value = dtVD.Rows(0).Item("JV_ACC_NAME").ToString.Trim
dgvAccDetail.Rows(0).Cells(2).Value = dtVD.Rows(0).Item("DEBIT").ToString.Trim
dgvAccDetail.Rows(0).Cells(3).Value = dtVD.Rows(0).Item("CREDIT").ToString.Trim
If you insist on manually assigning the cell values, you cannot just do row 0 (that's the first row). You need to do all the rows in a loop.
For i as Integer = 0 to dtVD.Rows.Count - 1
dgvAccDetail.Rows(i).Cells(0).Value = dtVD.Rows(i).Item("JV_CODE").ToString.Trim
dgvAccDetail.Rows(i).Cells(1).Value = dtVD.Rows(i).Item("JV_ACC_NAME").ToString.Trim
dgvAccDetail.Rows(i).Cells(2).Value = dtVD.Rows(i).Item("DEBIT").ToString.Trim
dgvAccDetail.Rows(i).Cells(3).Value = dtVD.Rows(i).Item("CREDIT").ToString.Trim
Next

Capturing an event such as mouse click in Datagridview in VB

Update 5/21/17. Thank you for the suggestion of using a Table. That was helpful. I actually figured it out. I made myinputable a global variable by declaring the Dim statement at the top and making it a Datagridview type. Now I can turn it off in the other event that I needed to do it.
I am a novice. I have created a Datagridview in VB 2015 to capture a bunch of data from the use. When the user is finished with the data entry, I want to store the cell values in my variables. I do not know how to capture any event from my dynamically created datagridview "myinputable." My code is below. Please help.
Private Sub inputmodel()
Dim prompt As String
Dim k As Integer
'
' first get the problem title and the number of objectives and alternatives
'
prompt = "Enter problem title: "
title = InputBox(prompt)
prompt = "Enter number of criteria: "
nobj = InputBox(prompt)
prompt = "Enter number of alternatives: "
nalt = InputBox(prompt)
'
' now create the table
'
Dim Myinputable As New DataGridView
Dim combocol As New DataGridViewComboBoxColumn
combocol.Items.AddRange("Increasing", "Decreaing", "Threashold")
For k = 1 To 6
If k <> 2 Then
Dim nc As New DataGridViewTextBoxColumn
nc.Name = ""
Myinputable.Columns.Add(nc)
Else
Myinputable.Columns.AddRange(combocol)
End If
Next k
' now add the rows and place the spreadsheet on the form
Myinputable.Rows.Add(nobj - 1)
Myinputable.Location = New Point(25, 50)
Myinputable.AutoSize = True
Me.Controls.Add(Myinputable)
FlowLayoutPanel1.Visible = True
Myinputable.Columns(0).Name = "Name"
Myinputable.Columns(0).HeaderText = "Name"
Myinputable.Columns(1).Name = "Type"
Myinputable.Columns(1).HeaderText = "Type"
Myinputable.Columns(2).Name = "LThresh"
Myinputable.Columns(2).HeaderText = "Lower Threshold"
'Myinputable.Columns(2).ValueType = co
Myinputable.Columns(3).Name = "UThresh"
Myinputable.Columns(3).HeaderText = "Upper Threshold"
Myinputable.Columns(4).Name = "ABMin"
Myinputable.Columns(4).HeaderText = "Abs. Minimum"
Myinputable.Columns(5).Name = "ABMax"
Myinputable.Columns(5).HeaderText = "Abs. Maximum "
Myinputable.Rows(0).Cells(0).Value = "Help"
If Myinputable.Capture = True Then
MsgBox(" damn ")
End If
End Sub
As #Plutonix suggests, you should start by creating a DataTable. Add columns of the appropriate types to the DataTable and then bind it to the grid, i.e. assign it to the DataSource of your grid, e.g.
Dim table As New DataTable
With table.Columns
.Add("ID", GetType(Integer))
.Add("Name", GetType(String))
End With
DataGridView1.DataSource = table
That will automatically add the appropriate columns to the grid if it doesn't already have any, or you can add the columns in the designer and set their DataPropertyName to tell them which DataColumn to bind to. As the user makes changes in the grid, the data will be automatically pushed to the underlying DataTable.
When you're done, you can access the data via the DataTable and even save the lot to a database with a single call to the Update method of a data adapter if you wish.

Rowdata not visible in telerik radGrid view

I have a RasGridView with 2 rows of data fetched from SQL to be displayed in the grid.
If oSQL.IsConnected Then
Try
ds = oSQL.GetDataSet("Select * from calc_umns order by calc_id", CommandType.Text)
If ds.Tables(0).Rows.Count > 0 Then
ds.Tables(0).TableName = "getSavedCalc"
RadGridView1.MasterGridViewTemplate.AutoGenerateColumns = False
RadGridView1.DataSource = ds
RadGridView1.DataMember = "getSavedCalc"
End If
Catch ex As Exception
End Try
End If
But the grid shows two rows with no data in it. could anyone guide where I am going wrong?
The FieldName property should be SET unique name and field value doesn't correspond to the SQL column names only FieldName property does.

Add default Item to data bound ComboBox

I have a function that brings back a datatable [GetDrinks()]
I use the function to populate a data source.
I want add a default value 'Select Drink' but it doesn't seem to work as it only shows the values form the datagrid.
Any ideas to get around this?
cboDrinks.DataSource = GetDrinks()
cboDrinks.DisplayMember = "Drink_DESCN"
cboDrinks.ValueMember = "Drink_ID"
cboDrinks.Items.Insert(0, " Select Drink ")
cboDrinks.SelectedIndex = 0
Per my comment, you need to insert the data into the DataTable that you are getting from GetDrinks:
Dim dt As DataTable = GetDrinks()
Dim row as DataRow = dt.NewRow
row("Drink_ID") = 0
row("Drink_DESCN") = " Select Drink "
dt.Rows.InsertAt(row, 0)
cboDrinks.DisplayMember = "Drink_DESCN"
cboDrinks.ValueMember = "Drink_ID"
cboDrinks.DataSource = dt
cboDrinks.SelectedIndex = 0
Note: Set the DisplayMember and ValueMember before the DataSource to avoid multiple refresh calls to the control.