Showing posts with label XtraGrid. Show all posts
Showing posts with label XtraGrid. Show all posts

Tuesday, January 12, 2016

How to export XtraGrid to excel with cell and row styles?

Scenario:

In current implementation, I have applied custom style using the GridView_RowCellStyle event e.g. text formatting and background color. Then I was trying to export the grid to excel file but all of the applied styles lost.

Solution:

To solve this problem which was looking huge by doing a small correction in implementation in never version of DevExpress controls. I set the DevExpress.Export.ExportSettings.DefaultExportType property to WYSIWYG and tried to export it again. Now I found all the changes as I have applied through customization.

Tuesday, July 7, 2015

How to iterate through TileView items in XtraGrid?

This is related to DevExpress question - How to loop through tiles in TileView, which help me to achieve the required functionality in the XtraGrid using the TileView. I require to implement the selection process for TileView similar to GridView in XtraGrid, but I require to iterate through all the TileView items. TileView actually use TileViewControl internally so it require to access under laying  tileview control items to access more information about the TileViewItems. See the below code snippet:

private void HandleTileItemSelection(TileViewItem tileViewItem)
{
if ((ModifierKeys & Keys.Control) != Keys.Control)
{
Dictionary visibleTiles = ((tileView1.GetViewInfo() as ITileControl).ViewInfo as TileViewInfoCore).VisibleItems;
int alternateCheckedItemsCount = 0;
foreach (KeyValuePair item in visibleTiles)
{
if (item.Value != tileViewItem && item.Value.Checked)
{
alternateCheckedItemsCount++;
item.Value.Checked = false;
tileView1.SetRowCellValue(item.Value.RowHandle, "CheckedStatus", false);
}
}
}
}

Thursday, July 7, 2011

make a XtraGrid cell read-only on condition

using System;
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing;  
using System.Text; 
using System.Windows.Forms; 
using DevExpress.XtraGrid.Views.Grid; 
namespace ReturnForm
 {
      public partial class Form1 : Form {
          public ReturnForm()   
          {
              InitializeComponent();
          }
          private void Form1_Load(object sender, EventArgs e)
          {
              FillDataSource();
          } 
          private void FillDataSource()
          {
              dtProducts = dsProducts.dtProductsTableAdapter.Fill( 
                                                this.dsProducts.dtProducts);
          }
          private bool IsShipToUSCanada(GridView view, int row)
          {
              try
            {
                    string val = Convert.ToString(
                                view.GetRowCellValue(row, "ShipCountry"));
                  return (val == "US" || val == "Canada");
              }
             catch( )
            {
                  return false;
            }
      }
         private void grvProducts_ShowingEditor(object sender, CancelEventArgs e)
        {
              if(gridView1.FocusedColumn.FieldName == "IsFreeShipping" 
                 && IsShipToUSCanada(grvProducts, grvProducts.FocusedRowHandle))
                  e.Cancel = true;
       }
        private void grvProducts_RowCellStyle(object sender,
                      DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
        { 
             if(e.Column.FieldName == "IsFreeShipping" 
                               && IsShipToUSCanada(grvProducts, e.RowHandle))
            {
                  e.Appearance.BackColor = Color.LightGray; 
             } 
         }
      }
  }

Tuesday, May 10, 2011

Selecting Row from XtraGrid with Object type DataBinding.

private void gridView1_FocusedRowChanged(object sender, |
              DevExpress.XtraGrid.Views.Base.
FocusedRowChangedEventArgs e)
{
GridView view = sender as GridView;
if (view.SelectedRowsCount > 0) // i there a selected Row?
{
    Contacts indirectContact = (Contacts)view.GetRow(e.FocusedRowHandle);
    currentSelectedContactId =
Convert.ToString(Contact.ContactID);
}

 

Friday, May 6, 2011

How to make XtraGrid GridControl Columns ReadOnly

Here are several possible solutions.
1. The first solution is to set the Editable option of the GridView.OptionsBehavior property
    to False. In this case, the whole grid becomes read-only.
    Select GridControl and click on the arrow on right-top select Run Designer. In the Properties
    List go to Options->OptionsBehaviour->Editable= False.. set this property to false.

2. Another solution is to cahnge the ReadOnly or AllowEdit option of your columns.
3. The last solution is to use the ShowingEditor event of the view and disable cell editing via
    code using the event handler's e.Cancel parameter.
The OptionsColumn property is part of the GridColumn class.

Open the designer for a GridControl, select a GridView, then click on the Columns icon in the Main section of the NavBar shown at
the left of the designer. This is where you manage your GridColumn objects for the selected GridView. Near the bottom of the
property list on the right side of the designer will be shown the options for a selected column.

Programmatically, you may do the following to make all columns read-only (C#):

foreach( GridColumn gridColumn in gridView1.Columns )
gridColumn.OptionsColumn.ReadOnly = true;