C# Samples

  • .Net DataGrid combobox. Auto-fill and Dictionary.
  • .Net XP DataGrid Button column Style.
  • .Net DataGrid Simple Sample.
  • .Net DataGrid Memo column Style.
  • .Net DataGrid DateTimePicker column Style.
  • How to Trap the Tab Key in a .NET Control?
  • How to format a datagrid column using a Date/Time format? How to update data in the column?
  • How to format a datagrid column using a Numeric format? How to update data in the column?
  • How to mask the data in a DataGrid Data column? How to mask the phone number (SSN, IP address) data?
  • How to draw a line in .NET? Line Control for .NET
  • DataGridColumns .NET assembly (Forms)
    More about DataGridColumns.dll
    Download DataGridColumns.dll
    Order DataGridColumns.dll

    ASP DataGridColumns .NET assembly
    More about ASPDataGridColumns.dll
    Download ASPDataGridColumns.dll
    Order ASPDataGridColumns.dll

    XML Converter is available!
    More about XML Converter
    Download XML Converter
    Order XML Converter

    .Net DataGrid combobox. Auto-fill and Dictionary. Download VB.NET and C# samples

    The sample introduces how to add a DataGridColumnStyle that contains combobox to a DataGrid on your .Net form. It is not just a dropdown combobox, which appears when a datagrid cell becomes the current cell. This .Net DataGrid DataGridColumnStyle combobox control has the following attractive features:

    This combobox DataGridColumnStyle automatically fills the text at the cursor with the value of its dropdown values list. As characters are typed, the component finds the closest matching item from the list and automatically fills in the remaining characters. Appended characters are highlighted so that they are replaced by any further typing. For this auto-filling feature you can setup the character case sensibility.

    This DataGridColumnStyle gives you ability to instantly update dropdown values with a really simple and friendly user interface. When you click the additional dropdown button of the combo a dictionary of its list values will be displayed below the combo. You can update values, and insert and delete rows in the dictionary grid.

    The control gives an ability to get a nesting combo box that filters values from a related child table. In a dictionary grid, you can view and edit related data in a child table. In your database a Master table has a one-to-many relationship with a Child table; so for each row of the Master table in Dictionary grid, you or your customer can view and edit the related rows of the Child table in a dictionary grid.

    You can turn off all or some of these features and use the combobox DataGridColumnStyle just as an easy dropdown DataGrid combobox.

    You can set its DataSource, DisplayMember, and ValueMember to bind the combobox to a foreign table.

    Download the dropdown combobox samples for Download VB.NET and C# that show how you can use a combobox in a .Net datagrid.

    // Set column styles
    // Set datagrid ColumnStyle for Car field
    DataGridTextBoxColumn colCar = new DataGridTextBoxColumn();
    colCar.MappingName = "Car";
    colCar.HeaderText = "Car Name";
    colCar.Width = 130;
    colCar.NullText = String.Empty;
    colCar.ReadOnly = true;
    TblStyle.GridColumnStyles.Add(colCar);

    // Set datagrid ComboBox ColumnStyle for PubID field
    DataTable tblCompanies = ds.Tables["Companies"];
    TblStyle.GridColumnStyles.Add(new DataGridComboBoxColumn(ref tblCompanies, 1, 0, true, false, true));
    // Datagrid ComboBox DisplayMember field has order number 1. Name of this column is "Name"
    // Datagrid ComboBox ValueMember field has order number 0. Name of this column is "PubID"
    TblStyle.GridColumnStyles[1].MappingName = "PubID";
    TblStyle.GridColumnStyles[1].HeaderText = "Company ID";
    TblStyle.GridColumnStyles[1].Width = 200;
    TblStyle.GridColumnStyles[1].NullText = String.Empty;

    // Set datagrid combobox ColumnStyle for State field
    DataTable tblStates = ds.Tables["States"];
    TblStyle.GridColumnStyles.Add(new DataGridComboBoxColumn(ref tblStates, 0, 0, true, false, false));
    // Datagrid ComboBox DisplayMember field has order number 0. Name of this column is "State"
    // Datagrid ComboBox ValueMember field has order number 0. It is the same column like for DisplayMember
    TblStyle.GridColumnStyles[2].MappingName = "State";
    TblStyle.GridColumnStyles[2].HeaderText = "State";
    TblStyle.GridColumnStyles[2].Width = 45;
    TblStyle.GridColumnStyles[2].NullText = String.Empty;

    // Set datagrid XP Style Button ColumnStyle for City field
    TblStyle.GridColumnStyles.Add(new DataGridXPButtonColumn());
    // Also you may set datagrid Button ColumnStyle for City
    // field without XP Button Style as the following:
    // .Add(New DataGridButtonColumn())
    TblStyle.GridColumnStyles[3].MappingName = "City";
    TblStyle.GridColumnStyles[3].HeaderText = "City";
    TblStyle.GridColumnStyles[3].Width = 60;
    TblStyle.GridColumnStyles[3].NullText = String.Empty;

    // Set datagrid Memo ColumnStyle for Comments field
    TblStyle.GridColumnStyles.Add(new DataGridMemoColumn("Car description"));
    TblStyle.GridColumnStyles[4].MappingName = "Comments";
    TblStyle.GridColumnStyles[4].HeaderText = "Comments";
    TblStyle.GridColumnStyles[4].Width = 60;

    Learn more about DataGridColumns assembly

    .Net DataGrid XP Button column Style.

    DataGridXPButtonColumn allows you to provide the datagrid interface your users are requesting, while supporting the utterly powerful Microsoft .NET DataGrid control. The DataGridXPButtonColumn makes the MS .NET DataGrid control one of the most powerful controls that you ever had used. A RustemSoft DataGridXPButtonColumn column in a .net DataGrid control gives you ability to define custom functionality for items in the grid beyond the edit, delete, select, and hyperlink features of other column types. For example, you can use a DataGridXPButtonColumn to create a "Link to a website" button.
    The DataGridXPButtonColumn has a pushbutton-style only. The button captions can be a text read from a database.
    When you define a button column, you specify a command associated with the button. When users click the button, the button's command is passed to a container where you can handle it with your custom code.

    Download the DataGridXPButtonColumn style samples for Download VB.NET and C# that show how you can use additional column styles in .Net datagrid.

    // Set column styles
    // Set datagrid ColumnStyle for Car field
    DataGridTextBoxColumn colCar = new DataGridTextBoxColumn();
    colCar.MappingName = "Car";
    colCar.HeaderText = "Car Name";
    colCar.Width = 130;
    colCar.NullText = String.Empty;
    colCar.ReadOnly = true;
    TblStyle.GridColumnStyles.Add(colCar);

    // Set datagrid ComboBox ColumnStyle for PubID field
    DataTable tblCompanies = ds.Tables["Companies"];
    TblStyle.GridColumnStyles.Add(new DataGridComboBoxColumn(ref tblCompanies, 1, 0, true, false, true));
    // Datagrid ComboBox DisplayMember field has order number 1. Name of this column is "Name"
    // Datagrid ComboBox ValueMember field has order number 0. Name of this column is "PubID"
    TblStyle.GridColumnStyles[1].MappingName = "PubID";
    TblStyle.GridColumnStyles[1].HeaderText = "Company ID";
    TblStyle.GridColumnStyles[1].Width = 200;
    TblStyle.GridColumnStyles[1].NullText = String.Empty;

    ......................

    // Set datagrid XP Style Button ColumnStyle for City field
    TblStyle.GridColumnStyles.Add(new
    DataGridXPButtonColumn(SystemColors.ControlText, SystemColors.Control));
    // Also you may set datagrid Button ColumnStyle for City
    // field without XP Button Style as the following:
    // .Add(New DataGridButtonColumn())
    TblStyle.GridColumnStyles[3].MappingName = "City";
    TblStyle.GridColumnStyles[3].HeaderText = "City";
    TblStyle.GridColumnStyles[3].Width = 60;
    TblStyle.GridColumnStyles[3].NullText = String.Empty;

    ......................

    // DataGridButtonAction function runs when the datagrid ButtonColumnStyle's
    // Button control is clicked. The function receives two arguments:
    // ColumnMappingName and ColumnValueAtRow of String type
    public void DataGridButtonAction(String ColumnMappingName, String ColumnValueAtRow)
    {
    // You can identify datagrid column mapping name.
    // It gives you ability to put several datagrid Button ColumnStyles on the same datagrid
    if (ColumnMappingName == "City") {
    String strValue;
    if (DataGrid1[DataGrid1.CurrentRowIndex, 3] == DBNull.Value) {
    strValue = "Nothing :(";
    }
    else {
    strValue = ColumnValueAtRow + " city, " + DataGrid1[DataGrid1.CurrentRowIndex, 2] + "!";
    }
    MessageBox.Show("You have chosen " + strValue, "DataGrid Button is clicked!");
    }
    }


    Learn more about DataGridColumns assembly

    .Net DataGrid Memo column Style.

    DataGridMemoColumn style gives you a useful Memo Field control, which presents an edit window when user selects a cell of the DataGrid Memo Column on .NET DataGrid. This provides a pop-up memo field editor that you can call from your code at any time to let users edit the text in a memo field.
    This Memo field editor provides more flexibility by updating the memo field to be used in a .NET DataGrid column.
    The DataGrid Memo Column Memo field editor is useful for showing short document contents, like memos and emails.
    When using the DataGrid Memo Column editor you are automatically provided with all general features, which any typical, contemporary word processor has.

    Download the DataGridMemoColumn .NET DataGrid Memo Field control samples for Download VB.NET and C# that show how you can use additional column styles in .Net datagrid.

    // Set column styles
    // Set datagrid ColumnStyle for Car field
    DataGridTextBoxColumn colCar = new DataGridTextBoxColumn();
    colCar.MappingName = "Car";
    colCar.HeaderText = "Car Name";
    colCar.Width = 130;
    colCar.NullText = String.Empty;
    colCar.ReadOnly = true;
    TblStyle.GridColumnStyles.Add(colCar);

    // Set datagrid ComboBox ColumnStyle for PubID field
    DataTable tblCompanies = ds.Tables["Companies"];
    TblStyle.GridColumnStyles.Add(new DataGridComboBoxColumn(ref tblCompanies, 1, 0, true, false, true));
    // Datagrid ComboBox DisplayMember field has order number 1. Name of this column is "Name"
    // Datagrid ComboBox ValueMember field has order number 0. Name of this column is "PubID"
    TblStyle.GridColumnStyles[1].MappingName = "PubID";
    TblStyle.GridColumnStyles[1].HeaderText = "Company ID";
    TblStyle.GridColumnStyles[1].Width = 200;
    TblStyle.GridColumnStyles[1].NullText = String.Empty;

    .................................................

    // Set datagrid Memo ColumnStyle for Comments field
    TblStyle.GridColumnStyles.Add(new DataGridMemoColumn("Car description"));
    TblStyle.GridColumnStyles[4].MappingName = "Comments";
    TblStyle.GridColumnStyles[4].HeaderText = "Comments";
    TblStyle.GridColumnStyles[4].Width = 60;

    Learn more about DataGridColumns assembly

    .Net DataGrid DateTimePicker column Style.

    The DateTimePicker ColumnStyle is used to allow the user to select a date and time, and to display that date/time in your DataGrid.

    Download the DataGrid DateTimePicker column Style samples for Download VB.NET and C# that show how you can use additional column styles in .Net datagrid.

    // Set datagrid ComboBox ColumnStyle for PubID field
    DataTable tblCompanies = ds.Tables["Companies"];
    TblStyle.GridColumnStyles.Add(new DataGridComboBoxColumn(ref tblCompanies, 1, 0, true, false, true));
    // Datagrid ComboBox DisplayMember field has order number 1. Name of this column is "Name"
    // Datagrid ComboBox ValueMember field has order number 0. Name of this column is "PubID"
    TblStyle.GridColumnStyles[1].MappingName = "PubID";
    TblStyle.GridColumnStyles[1].HeaderText = "Company ID";
    TblStyle.GridColumnStyles[1].Width = 200;
    TblStyle.GridColumnStyles[1].NullText = String.Empty;

    .................................................

    // Set datagrid DateTimePicker ColumnStyle for DateFirst field
    TblStyle.GridColumnStyles.Add(new DataGridDateTimePicker());
    TblStyle.GridColumnStyles[4].MappingName = "DateFirst";
    TblStyle.GridColumnStyles[4].HeaderText = "Date";
    TblStyle.GridColumnStyles[4].Width = 60;

    Learn more about XP Style Button Control and DataGridColumns assembly

    How to Trap the Tab Key in a .NET Control?

    You are trying to create a control in .NET, and your control has to catch the Tab key. It might be a grid, where you would expect Tab to move between cells, or it might be an editor control. Now you would like to catch Tab and some other navigation keys that do not call OnKeyDown or OnKeyUp. How to intercept Tabs properly in .NET?
    You have to create a class that inherits from the System.Windows.Forms.Control and override the ProcessKeyMessage method. This method is called when a control receives a keyboard message. You suppose to trap the Tab on your Button. Just override the System.Windows.Forms.Button class and create your own myButton class:

    public class myButton : System.Windows.Forms.Button
    {
    public int PreProcessKey;

    public myButton()
    {
    }

    protected override bool ProcessKeyMessage(ref System.Windows.Forms.Message m)
    {
    PreProcessKey = m.WParam.ToInt32();
    return true;
    }
    }


    In your custom code you will be able to identify which key has been pressed before your button was activated:


    if (System.Windows.Forms.Keys.Tab.Equals(myButton.PreProcessKey)) MessageBox.Show("Tab is pressed!");

    Learn more about DataGridColumns assembly

    How to format a datagrid column using Numeric, DateTime formats? How to mask data in the column?

    These formatted intelligent DateTimeColumn, NumericColumn, TextFractionsColumn style controls can mask the date, time, numbers, digits, decimal as well as the text fractions. It gives you ability to manage the IP Address, SS#, Phone numbers, etc., and checks the validation, and automatically set the delimiter location.

    // Set datagrid DateTime ColumnStyle for TimeFirst field
    TblStyle.GridColumnStyles.Add(new DataGridDateTimeColumn(DateTimeTextBox.Stencils.HHMM24, DateTime.Now, ":"));
    //TblStyle.GridColumnStyles.Add(new DataGridTextBoxColumn());
    TblStyle.GridColumnStyles[6].MappingName = "TimeFirst";
    TblStyle.GridColumnStyles[6].HeaderText = "Time";
    TblStyle.GridColumnStyles[6].Width = 40;
    TblStyle.GridColumnStyles[6].NullText = String.Empty;

    // Set datagrid Numeric ColumnStyle for Price field
    TblStyle.GridColumnStyles.Add(new DataGridNumericColumn(false, true, null, null, 1000000, null, 2));
    //TblStyle.GridColumnStyles.Add(new DataGridTextBoxColumn());
    TblStyle.GridColumnStyles[7].MappingName = "Price";
    TblStyle.GridColumnStyles[7].HeaderText = "Price";
    TblStyle.GridColumnStyles[7].Width = 60;
    TblStyle.GridColumnStyles[7].NullText = String.Empty;

    // Set datagrid TextFractions ColumnStyle for Phone field
    TblStyle.GridColumnStyles.Add(new DataGridTextFractionsColumn());
    TblStyle.GridColumnStyles[8].MappingName = "Phone";
    TblStyle.GridColumnStyles[8].HeaderText = "Phone";
    TblStyle.GridColumnStyles[8].Width = 80;
    TblStyle.GridColumnStyles[8].NullText = String.Empty;

    // Add TableStyle
    DataGrid1.TableStyles.Add(TblStyle);

    // Define NumericColumn DataGridNumericColumn object for Price field
    DataGridNumericColumn NumericColumn = (DataGridNumericColumn) DataGrid1.TableStyles[0].GridColumnStyles[7];
    // Specify back color for the field
    NumericColumn.txtBox.box.BackColor = System.Drawing.Color.LightPink;

    // Identify PhoneColumn object that is the DataGridTextFractionsColumn?s ?child?
    DataGridTextFractionsColumn PhoneColumn = (DataGridTextFractionsColumn) DataGrid1.TableStyles[0].GridColumnStyles[8];
    // Specify Delimiter Character for the field
    PhoneColumn.txtBox.box.DelimiterChar = "-";

    // Specify first fraction properties
    // Alphanumeric symbols only are acceptable for the fraction
    PhoneColumn.txtBox.box.FractionsCode[0, 0] = "a";
    // You can insert 3 symbols only into the first fraction
    PhoneColumn.txtBox.box.FractionsCode[0, 1] = 3;

    // Specify second fraction properties
    // Numeric symbols only are acceptable for the fraction
    PhoneColumn.txtBox.box.FractionsCode[1, 0] = "n";
    // You can insert 3 symbols only into the second fraction
    PhoneColumn.txtBox.box.FractionsCode[1, 1] = 3;

    // Specify third fraction properties
    // Numeric symbols only are acceptable for the fraction
    PhoneColumn.txtBox.box.FractionsCode[2, 0] = "n";
    // You can insert 4 symbols only into the third fraction
    PhoneColumn.txtBox.box.FractionsCode[2, 1] = 4;

    // To specify Password column only one text fraction must be defined:
    // To let accept any symbols for the fraction we need leave first array element empty:
    //PhoneColumn.txtBox.box.FractionsCode[0, 0] = "";
    // You can insert 30 symbols only into the password fraction
    //PhoneColumn.txtBox.box.FractionsCode[0, 1] = 30;
    // Specify Password Character for the field
    //PhoneColumn.txtBox.box.PasswordChar = "*";

    Learn more about DataGridColumns assembly

    How to draw a line in .NET? Line Control for .NET

    When a beginner who has VB6 experience first time opens .NET and just going about making a form up he/she could notice there is no Line in the .NET toolbox. What happened, where did it go?
    There is a difference from VB6 forms that Windows Forms .NET does not support the Line control.

    The Line class is based on System.Drawing namespace that provides access to GDI+ basic graphics functionality. A Line control is a graphical control that displays a horizontal, vertical, or diagonal one-pixel-wide line that can't be changed directly. The Line control can be changed dynamically at run time.
    The control class Line that is implemented in both languages (VB.Net and C#) is derived from System.Windows.Forms.Control. It overrides the OnPaint method to draw itself. The class will draw the line depending on its properties.

    Line controls can be displayed on forms, in picture boxes, and in another visual controls. You can move or resize your Line object by altering its X_Left, X_Right, Y_Left, and Y_Right properties. Also you can setup its Color property.

    Line ln = new Line();
    ln.X_Left = 20;
    ln.Y_Left = 150;
    ln.X_Right = 100;
    ln.Y_Right = 10;
    ln.Color = Color.Blue;

    Download the Line Control samples for VB.NET and C#


    Visual Basic News and Information Source - www.VBWire.com




    Copyright © 2001-2022 RustemSoft

    ODBC compliant data source such as SQL Server, ORACLE, MySQL and many more.
    You do not need programming knowledge to use the product. It is purposed at non-technical users who may be not familiar with XML. The interface is designed to promote a step by step approach and hide most of the technical issues.
    The more technically capable can enter SQL directly if needed to extract data for conversion. Also there are bunch of options for tailoring the XML output to meet most requirements. You can even write your own XSL and automatically transform the XML produced.
    There are two options available for integration into web sites or other systems. There is a GUI executable and a command line utility. Both of them allow execution of predefined transformations.
    XML Converter takes care of frequent XML creation with single, easy method support for exporting data to XML. The output file is a well-formed XML from a standard template, and may come (if you need) with a standard eXtensible Style Language (XSL) sheet to render the output to HTML-view using the well-known MS Internet Explorerr and a latest version of Netscape Navigatorr. The XSL give you ability to extract, transform and render the content of an XML file. And now this specification is supported by popular of Internet browsers and you do not need a physical transformation your XML document into HTML files.