RSS

Category Archives: WinForm

devexpress multiple gridview export to excel in Single File winforms


After two much searching of this solution to export multiple gridview data to single Excel file with separate Sheet of Excel.

Then i find this solution which resolve my problem. this is 100% tested and use in my project . after that i share with you in both language c# and vb.net.

 

 Solution :: Vb.Net

Imports DevExpress.XtraPrinting
Imports DevExpress.XtraPrintingLinks

 

Public Sub MultiFileExportToExcel()

Using saveDialog = New SaveFileDialog()
saveDialog.Filter = “Excel (.xlsx)|*.xlsx”
If saveDialog.ShowDialog() = DialogResult.OK Then
Dim printingSystem = New PrintingSystemBase()
Dim compositeLink = New CompositeLinkBase()
compositeLink.PrintingSystemBase = printingSystem

Dim link1 = New PrintableComponentLinkBase()
link1.Component = grid1
Dim link2 = New PrintableComponentLinkBase()
link2.Component = grid2

compositeLink.Links.Add(link1)
compositeLink.Links.Add(link2)

Dim options = New XlsxExportOptions()
options.ExportMode = XlsxExportMode.SingleFilePageByPage

compositeLink.CreatePageForEachLink()
compositeLink.ExportToXlsx(saveDialog.FileName, options)
End If
End Using
End Sub

 

Solution ::  C#

using DevExpress.XtraPrinting
using DevExpress.XtraPrintingLinks

public void exportToExcel()
{
using (var saveDialog = new SaveFileDialog())
{
saveDialog.Filter = “Excel (.xlsx)|*.xlsx”;
if (saveDialog.ShowDialog() == DialogResult.OK)
{
var printingSystem = new PrintingSystemBase();
var compositeLink = new CompositeLinkBase();
compositeLink.PrintingSystemBase = printingSystem;

var link1 = new PrintableComponentLinkBase();
link1.Component = grid1;
var link2 = new PrintableComponentLinkBase();
link2.Component = grid2;

compositeLink.Links.Add(link1);
compositeLink.Links.Add(link2);

var options = new XlsxExportOptions();
options.ExportMode = XlsxExportMode.SingleFilePageByPage;

compositeLink.CreatePageForEachLink();
compositeLink.ExportToXlsx(saveDialog.FileName, options);
}
}
}

 

Reference url;

https://www.devexpress.com/Support/Center/Question/Details/A2730

 
Leave a comment

Posted by on April 22, 2015 in Vb.Net, WinForm

 

Tags: ,

Devexpress Gridview RepositoryItemCheckEdit changes immediatelly


If you have a Gridview with the first column edited with an RepositoryItemCheckEdit and with the datasource an runtime created datatable.
What I want to obtain and I not succeeded yet is to count the rows from the datatable with check on the first column and put the result in a labelimmediatelly after user changes check state of repository.

but if you check/Uncheck checkbox   RepositoryItemCheckEdit  Event then your Count not match with Gridview Checkbox.if you use different event of Gridview . the solution of your problem is..

[VB.NET]
Private Sub repositoryItemCheckEdit1_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs)
    gridView1.PostEditor()
    CountChecked()
End Sub

The PostEditor method posts the edited value to the underlying source. I’ve attached a sample demonstrating how it works. Please test it and let us know your result.

the CountChecked method as follows:

[VB.NET]
Private Sub CountChecked()
    Dim checkedCount As Integer = 0
    Dim dt As DataTable = CType(gridControl1.DataSource, DataTable)
    For i As Integer = 0 To dt.Rows.Count - 1
        If CBool(dt.Rows(i)("Check")) Then
            checkedCount += 1
        End If
    Next i
    labelControl1.Text = "Checked: " & checkedCount.ToString()
End Sub

Reference :

https://www.devexpress.com/Support/Center/Question/Details/Q583442

 

 

 

 

 

 

 
1 Comment

Posted by on July 4, 2014 in WinForm

 

Tags: ,

Disable Textbox Paste Option in Winform


If you want to disable paste option on text box in Winform Application then this code very helpful for you.

Vb.Net
Private Sub txtbarcode_KeyDown(sender As Object, e As KeyEventArgs) Handles txtArabicName.KeyDown

If e.Control And e.KeyValue = 86 Then
e.Handled = True
e.SuppressKeyPress = True
End If
End Sub

 C#

private void txtbarcode_KeyDown(object sender, KeyEventArgs e)
{
	if (e.Control & e.KeyValue == 86) {
		e.Handled = true;
		e.SuppressKeyPress = true;


	}
}
 
Leave a comment

Posted by on May 27, 2014 in WinForm

 

Tags: , ,

How to disable the default Context Menu devexpress


If you want to Hide context menu on specific TextBoxt (Devexpress) Control then use this following Code,Write this code on Form Load Event

C#: 

ContextMenu emptyMenu = new ContextMenu();

this.components.Add(emptyMenu);

txtBardcode.Properties.ContextMenu = emptyMenu;

 VB.Net

 
Dim emptyMenu As New ContextMenu()

Me.components.Add(emptyMenu)

txtBardcode.Properties.ContextMenu = emptyMenu

 

 

 

ContextMenu

 
Leave a comment

Posted by on May 27, 2014 in WinForm

 

Tags: , ,

Could not load file or assembly ‘file:///C:\Program Files (x86)\SAP BusinessObjects\Crystal Reports for .NET Framework 4.0\Common\SAP BusinessObjects Enterprise XI 4.0\win32_x86\dotnet1\crdb_adoplus.dll’ or one of its dependencies. The system cannot find the file specified.


This Error give this message…..

This stuff basically happens, if you have correct setup of SBO (I wish you so:)), that between different components of your SBO SDK there are assemblies with different .NET version. Check if you have someold version of SAP BO SDK installed on your machine too. Hope this helps.

 

 

add this to your .config file (usually app.config)
<startup useLegacyV2RuntimeActivationPolicy=”true”>
<supportedRuntime version=”v4.0″ sku=”.NETFramework,Version=v4.0″/>

</startup>

 

RptError

 

 
Leave a comment

Posted by on January 17, 2014 in Crystal Report, WinForm

 

devexpress TextEdit: Automatic validation


if you want to validate E-mail runtime using devexpress TextEdit control. you use this mask for both web & winform.

 

Mask : [a-zA-Z0-9.-]+@[a-zA-Z0-9-]+\.[A-Za-z]{2,6}

I have added a Textbox like this:
<dxe:TextEdit EditValue=”{Binding Email}” MaskType=”RegEx” Mask=”[a-zA-Z0-9.-]+@[a-zA-Z0-9-]+\.[A-Za-z]{2,6}” />

As you can see it is using a regex to validate email adresses.
The mask is very nice, however i can easily tab out of the field resulting in invalid data being bound to my model.

Shouldnt it automatically Validate the mask on losing focus

 

Email Validate

 

 
Leave a comment

Posted by on December 16, 2013 in WinForm

 

Tags:

add an item to combobox before bind data


Solution 1:

DataTable dt = new DataTable();

// cboTown.Items.Clear();

if (obj.RowCount > 0)
{
// cboTown.Items.Insert(-1, “—-For All—-“);
dt = obj.DefaultView.Table;
DataRow row = dt.NewRow();
row[“town”] = “—-For All—-“;
row[“surveyformid”] = “0”;
dt.Rows.InsertAt(row, 0);

cboTown.DataSource = dt;
cboTown.DisplayMember = “town”;
cboTown.ValueMember = “surveyformid”;
this.cboTown.SelectedIndex = 0;
}

Solution 2;

DataTable table = new DataTable("myData");
using (SqlConnection conn = new SqlConnection(connString))
{
    using (SqlDataAdapter da = new SqlDataAdapter(@"SELECT * FROM MyTable", conn))
         da.Fill(table);
}

DataRow row  = table.NewRow();
row["town"] =  "Please select bellow...";
  row["surveyformid"] = "0";
table.Rows.InsertAt(row, 0); 
 cboTown.DataSource = table;
                cboTown.DisplayMember = "town";
                cboTown.ValueMember = "surveyformid";
                this.cboTown.SelectedIndex = 0;
  this.cboTown.SelectedIndex = 0;

Untitled
 
Leave a comment

Posted by on June 12, 2013 in WinForm

 

Tags: ,