Saturday, January 24, 2015

Telerik Winforms 2010 SP1 - RadGridView - Expand/Collapse Grouped Row with Single Click

Row grouping is supported by RadGridView. To expand/collapse a grouped row, user can double click the grouped row or single click the chevron icon chevron.
Sometimes you may want to expand/collapse a grouped row with a single click (just like Windows XP collapsible panel). To achieve this, here is the solution.
void radGridView_CellClick(object sender, GridViewCellEventArgs e)
{
 if (sender is Telerik.WinControls.UI.GridGroupExpanderCellElement)
  return;

 GridViewGroupRowInfo rowInfo = e.Row as GridViewGroupRowInfo;
 if (rowInfo == null)
  return;

 rowInfo.IsExpanded = !rowInfo.IsExpanded;
}

Pay attention to code in line 3 and 4, since RadGridView already handled single click event, in this event handler, we need to exclude it.


Create a Successful Online Store at Bigcommerce! Try it Free Now!

RadGridView - Customize the Text of Grouped Row

Default Format for Grouped Row Text in RadGridView


By default, RadGridView appends a ";" to the text of a grouped row, looking like:
remove-semicolon-from-grouped-row
It's pretty ugly.

Customized Grouped Row Text

To remove it, you need to implement the GroupSumaryEvaluate event handler with a customized format.
void radGridView_GroupSumaryEvaluate(object sender, GroupSummaryEvaluationEventArgs e)
{
 if (e.SummaryItem.FieldName == "Name")
 {
  e.FormatString = String.Format("Name: {0}", e.Value);
 }
}
Here is the final view:
remove-semicolon-from-grouped-row2


Create a Successful Online Store at Bigcommerce! Try it Free Now!

RadGridView - Show/Hide Columns Using Context Menu

Default Way to Show/Hide Columns in RadGridView

By default, to hide a column, user needs to click "Hide Column" in the context menu; to show a column, user needs to drag the column from the column chooser to the grid.


It's not a user-friendly way.

Use Context Menu to  Show/Hide Columns in RadGridView

In this article, I'll show how to show/hide columns using the context menu.
First, you need to register the event handler.
radGridView.ContextMenuOpening += new ContextMenuOpeningEventHandler(radGridView_ContextMenuOpening);
Next, add the implementation.
void radGridView_ContextMenuOpening(object sender, ContextMenuOpeningEventArgs e)
{
 if (e.ContextMenu == null || e.ContextMenu.Items == null)
  return;

 RadGridView radGridView = sender as RadGridView;

 if (radGridView == null)
  return;

 for (int i = 0; i < e.ContextMenu.Items.Count; i++)
 {
  if (e.ContextMenu.Items[i].Text == "Column Chooser" || e.ContextMenu.Items[i].Text == "Hide Column")
  {
   e.ContextMenu.Items[i].Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
  }
 }

 RadMenuItem hideColumnsMenuItem = new RadMenuItem();
 hideColumnsMenuItem.Text = "Show/Hide Columns";

 int noOfColumnVisible = 0;

 foreach (GridViewColumn col in radGridView.Columns)
 {
  if (col.IsVisible)
  {
   noOfColumnVisible++;
  }
 }

 foreach (GridViewColumn column in radGridView.Columns)
 {
  GridViewDataColumn col = column as GridViewDataColumn;

  if (col == null || col.IsGrouped)
   continue;

  CheckBoxTag checkBoxTag = new CheckBoxTag();

  checkBoxTag.ColumnName = col.UniqueName;
  checkBoxTag.ColumnWidth = col.Width;
  checkBoxTag.RadGridView = radGridView;
  checkBoxTag.RadMenuItem = hideColumnsMenuItem;

  RadCheckBoxElement columnVisibilityCheckBox = new RadCheckBoxElement();
  columnVisibilityCheckBox.MouseDown += new MouseEventHandler(columnVisibilityCheckBox_MouseDown);
  columnVisibilityCheckBox.Text = col.HeaderText;
  columnVisibilityCheckBox.Tag = checkBoxTag;

  if (column.IsVisible)
  {
   columnVisibilityCheckBox.ToggleState = ToggleState.On;

   if (noOfColumnVisible <= 1)
   {
    columnVisibilityCheckBox.Enabled = false;
   }
  }
  else
  {
   columnVisibilityCheckBox.ToggleState = ToggleState.Off;
  }

  hideColumnsMenuItem.Items.Add(columnVisibilityCheckBox);
 }

 e.ContextMenu.Items.Add(hideColumnsMenuItem);
}

void columnVisibilityCheckBox_MouseDown(object sender, MouseEventArgs e)
{
 RadCheckBoxElement checkBox = sender as RadCheckBoxElement;

 CheckBoxTag checkBoxTag = checkBox.Tag as CheckBoxTag;

 string name = checkBoxTag.ColumnName;
 RadGridView radGridView = checkBoxTag.RadGridView;
 RadMenuItem radMenuItem = checkBoxTag.RadMenuItem;

 GridViewDataColumn column = radGridView.Columns[name] as GridViewDataColumn;

 if (column == null)
  return;

 int noOfColumnVisible = 0;

 foreach (GridViewColumn col in radGridView.Columns)
 {
  if (col.IsVisible)
  {
   noOfColumnVisible++;
  }
 }

 if (noOfColumnVisible <= 1)
 {
  if (checkBox.ToggleState != ToggleState.On)
  {
   column.IsVisible = true;

   foreach (Object obj in radMenuItem.Items)
   {
    RadCheckBoxElement checkBox2 = obj as RadCheckBoxElement;

    if (checkBox2 == null)
     continue;

    checkBox2.Enabled = true;
   }
  }
 }
 else
 {
  if (checkBox.ToggleState == ToggleState.On)
  {
   column.IsVisible = false;

   noOfColumnVisible--;
   if (noOfColumnVisible == 1)
   {
    foreach (Object obj in radMenuItem.Items)
    {
     RadCheckBoxElement checkBox2 = obj as RadCheckBoxElement;

     if (checkBox2 == null)
      continue;

     CheckBoxTag checkBoxTag2 = checkBox2.Tag as CheckBoxTag;

     if (checkBoxTag2 == null)
      continue;

     string name2 = checkBoxTag2.ColumnName;
     RadGridView radGridView2 = checkBoxTag2.RadGridView;

     GridViewColumn column2 = radGridView2.Columns[name2] as GridViewColumn;

     if (column2 == null)
      continue;

     if (column2.IsVisible)
     {
      checkBox2.Enabled = false;
      break;
     }
    }
   }
  }
  else
  {
   column.IsVisible = true;
  }
 }
}

Then, add the class CheckBoxTag.
class CheckBoxTag
{
 public int ColumnWidth
 {
  set;
  get;
 }

 public string ColumnName
 {
  set;
  get;
 }

 public RadGridView RadGridView
 {
  set;
  get;
 }

 public RadMenuItem RadMenuItem
 {
  set;
  get;
 }
}

Illustration for Show/Hide Columns Using Context Menu

Finally, you could see the new menu item is added to the context menu with all columns inside it.
show-hide-columns
Now, just click the checkboxes to show/hide columns.


Create a Successful Online Store at Bigcommerce! Try it Free Now!

Manually Create SNMP v3 Users without Net-SNMP

Create SNMP v3 users without Net-SNMP

Follow these steps to manually (not using net-snmp) create SNMP v3 users in Cent OS:
1. Stop snmp daemon by execute 'service snmpd stop'.
2. Add the following to /var/lib/net-snmp/snmpd.conf
createUser (username) MD5 (password) DES (encryption password)
3. Add the following to /etc/snmp/snmpd.conf
rouser (username) authpriv .1
4. Start the snmp daemon.
Bear in mind that you need to stop snmp before making configuration changes.


Create a Successful Online Store at Bigcommerce! Try it Free Now!

JBoss7.1.1 JMS | JBoss AS 7.1.1 - JMS Configuration

This article summarizes the issues I encountered during migration of a JMS application
from JBoss 4.2.3 to 7.1.1.

Configure Messaging and Remoting Modules

Refer to this article: http://blog.avisi.nl/2012/10/10/configuring-camel-to-use-hornetq-in-jboss-as-7.

RMI Port

if you previously used something like jnp://localhost:1099/, you need change it to remote://localhost:4447.

Handle Exception: javax.security.sasl.SaslException: 

Authentication failed: all available authentication mechanisms failed.
You need to add a user under Application Realm or remove the authentication by removing security-realm="ApplicationRealm" from
<subsystem xmlns="urn:jboss:domain:remoting:1.1">
           <connector name="remoting-connector" socket-binding="remoting" security-realm="ApplicationRealm"/>
</subsystem>
in your standalone.xml.

Handle Exception: javax.jms.JMSSecurityException

Unable to validate user: null
You need to set "security-enabled" to false in the standalone.xml.
<subsystem xmlns="urn:jboss:domain:messaging:1.1">
     <hornetq-server>
         <security-enabled>false</security-enabled>
         ......
     </hornetq-server>
</subsystem>

Add System Properties

System properties can be added into standalone.xml.
<server>
<extensions>
</extensions>
<system-properties>
     <property name="propertyName" value="property value"/>
</system-properties>
</server>

Then, in your program, you can retrieve them using System.getProperty("propertyName").

Create JmsTemplate for Topics

<bean id="jmsTopicTemplate" class="org.springframework.jms.core.JmsTemplate">
   <constructor-arg ref="connectionFactory" />
   <property name="pubSubDomain" value="true"/>
</bean>

Summary of Dependent Libs

hornetq-core-2.2.13.Final.jar
hornetq-jms-2.2.13.Final.jar
jboss-remote-naming-1.0.2.Final.jar
netty-3.2.6.Final.jar
spreing-jms-3.2.5.RELEASE.jar

Check more details here.


Create a Successful Online Store at Bigcommerce! Try it Free Now!