Question

Il doit y avoir un moyen pour permettre la création et l'insertion d'un enregistrement à partir d'un AxGridView sans utiliser le tunnel et l'approche Assistant. D'après ce que j'ai trouvé sur Internet à ce jour, le seul exemple utilise un assistant, et honnêtement, je ne trouve pas que ce soit une approche conviviale.

Quelqu'un at-il essayé de permettre l'insertion d'enregistrements directement à partir d'un AxGridView?

Était-ce utile?

La solution

Oui il est possible d'entrer des données par AxGridView. Juste activer la modification, la suppression de ce contrôle. Et une chose à faire nouvelle ligne - vous devez faire addditional bouton - créer la nouvelle ligne, et le code derrière:

protected void NewLine_Click(object sender, EventArgs e)
{
    int editIdx = AxGridView1.EditIndex;      

    try
    {
        // Save the last unsaved line if any
        if (AxGridView1.EditIndex != -1 && AxGridView1.Rows.Count > 0)
        {
            this.AxGridView1.UpdateRow(AxGridView1.EditIndex, true); 
        }


        DataSetViewRow dsvr = this.dsv.AddNew();        
    }
    catch (System.Exception ex)
    {
        AxExceptionCategory exceptionCategory;

        if (!AxControlExceptionHandler.TryHandleException(this, ex, out exceptionCategory))
        {
            // Throw the fatal exception
            throw;
        }
        if (exceptionCategory == AxExceptionCategory.NonFatal)
        {
            AxGridView1.EditIndex = editIdx;
        }
    }
}

private DataSetView dsv //get dataset view
    {
        get
        {
            DataSet dataSet = this.AxDataSource1.GetDataSet();
            return dataSet.DataSetViews[this.AxGridView1.DataMember];
        }
    } 
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top