Home Forums WinForms controls Xceed Grid for WinForms CellEditor Property?

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #13893 |

    Forgive me — I’m very new to Xceed, so there is probably a very simple solution to this problem.

    That said, I’ve created a GridControl that will be used entirely for data entry. I manually added columns (by right-clicking and selecting “Add column (unbound)”) for each. I set the data type for each Column control and am seeing some CellEditors and validation happening (for dates and numeric data types) when I run the app.

    So far so good.

    However, I’d like to set a MaxLength for some Column controls that are String DataTypes and I can’t seem figure out how to do it. What I’ve seen says that the GridTextBox CellEditor has a MaxLength property. But, I can’t assign that as the CellEditor (which I believe it should be by default for a cell that’s a string data type). I don’t have CellEditor (or CellViewer, for that matter) as properties of either the DataCell or the Column. I tried manually adding it in the InitializeComponent procedure behind the scenes, but it was removed when I went back into the GUI editor and returned to the code.

    In the documentation, I ended up at the “Implementing the ICellEditor Interface” article, which is why I tried to manually update the code, as indicated above.

    Also, I searched the samples documentation and got no results with “GridTextBox” or “MaxLength” and the same article as above for “CellEditor”.

    Any help would be appreciated!

    Imported from legacy forums. Posted by billmonti (had 3536 views)

    User (Old forums)
    Member
    Post count: 23064

    You should never put your own code in InitializeComponent: it will always be removed by the Forms Designer. You can put it in the constructor of the Form, right after the call to InitializeComponent. Or, if you don’t want to put too much code in the constructor, create your own method and call that from the constructor. It would look like this:<code>public class MyForm : Form
    {
    public MyForm() {
    InitializeComponent();
    MyInitialize();
    }
    private void InitializeComponent() {
    // don’t touch this
    }
    private void MyInitialize() {
    // put your own initialize code here
    }
    }</code>There you can create the GridTextBox and assign it to the column(s), like this:<code>GridTextBox editor = new GridTextBox();
    editor.MaxLength = whatever;
    gridControl1.Columns[“column1”].CellEditor = editor;</code>

    Imported from legacy forums. Posted by Tommy (had 207 views)

    User (Old forums)
    Member
    Post count: 23064

    Tommy,

    Thanks for your quick response. I was excited to implement the CellEditors in my project. Unfortunately, this solution isn’t working for me.

    Here’s what I’m doing, as per your example:
    <pre>
    public class frmEnterInvoices : Form
    {
    public frmEnterInvoices()
    {
    InitializeComponent();
    InitializeCellEditors();
    }

    private void InitializeCellEditors()
    {
    //Vendor Number MaxLength (5)
    GridTextBox gtbVendorNumber = new GridTextBox();
    gtbVendorNumber.MaxLength = 5;
    dgInvoiceEntry.Columns[“colEntryVendorNumber”].CellEditor = gtbVendorNumber;
    }
    }
    </pre>

    However, I’m getting the following error:
    An unhandled exception of type ‘System.NullReferenceException’ occurred in [app].exe
    Additional information: Object reference not set to an instance of an object.

    …in the line where I assign the CellEditor to the Column. It seems as if the GridControl hasn’t rendered yet, so it doesn’t know what the Column is (even though this code is called after the InitializeComponent function, which creates the GridControl and all Columns).

    If you have any additional ideas, I’d love to hear them!

    Thanks,
    Bill

    Imported from legacy forums. Posted by billmonti (had 434 views)

    User (Old forums)
    Member
    Post count: 23064

    PS…

    I did double-check the spelling on my Column fieldName. 🙂 So, that wasn’t it.

    But I did just try using the Column index as the identifier and that seems to work just fine. Hmmm….:~

    I would like to be able to use the Column fieldName just because I’m not sure if the column orders will change (or fields will be added) and I don’t want to have to touch that section of code every time a change is made.

    Thanks again!

    Imported from legacy forums. Posted by billmonti (had 371 views)

    User (Old forums)
    Member
    Post count: 23064

    If you added the column in the Forms Designer in Visual Studio, your Form-class should have a field for each grid element. So if your column is named colEntryVendorNumber, you can access the column like this:<code>colEntryVendorNumber.CellEditor = gtbVendorNumber;</code>

    Imported from legacy forums. Posted by Tommy (had 4376 views)

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.