简体   繁体   English

数据网格视图的问题

[英]Problem with datagridView

hi i'm trying to select the the object associated to the row in my datagridview but it doesn't work and i wanna know what i'm doing wrong because for me the code it's fine嗨,我正在尝试 select 与我的 datagridview 中的行关联的 object 但它不起作用,我想知道我做错了什么,因为对我来说代码很好

        private System.Windows.Forms.DataGridView dataGridView1;
        private Prueba prueba;
        private System.Windows.Forms.BindingSource personaBindingSource2;
        private WindowsApplication1.PruebaTableAdapters.PersonaTableAdapter personaPrueba;

        //this code sets the binding source
        // personaBindingSource2
        // 
        this.personaBindingSource2.DataMember = "Persona";
        this.personaBindingSource2.DataSource = this.prueba;
        // prueba
        this.prueba.DataSetName = "Prueba";
        this.prueba.SchemaSerializationMode = System.Data.SchemaSerializationMode.IncludeSchema;
        this.dataGridView1.DataSource = this.personaBindingSource2;

this is the code associated to the event这是与事件关联的代码

    //this code it's execute when the users do click in a cell
    private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
    {
        DataGridViewRow row = dataGridView1.CurrentRow;

        Prueba prueba = row.DataBoundItem as Prueba; //this is the part that always have null and i don't know why the row have the values

        MessageBox.Show("hola");
    }

my database table it's like this我的数据库表是这样的

table Persona
nombre varchar,
cedula varchar,
IDPersona varchar

i really don't know if a need more code to help me with this trouble but idon't see the problem thanks for your help我真的不知道是否需要更多代码来帮助我解决这个问题,但我没有看到问题感谢您的帮助

Try DataGridView row = dataGridView1.SelectedRows[0];试试DataGridView row = dataGridView1.SelectedRows[0]; instead of the CurrentRow .而不是CurrentRow

i solve mi problem with this code my only problem was that i didn't know how to manipulate the data我用这段代码解决了我的问题 我唯一的问题是我不知道如何操作数据

//gets the current row
DataGridViewRow row = dataGridView1.CurrentRow;

//get's the info of the row
DataRowView algo = row.DataBoundItem as DataRowView;

//set's the type of the data
Prueba.PersonaRow prueba = algo.Row as Prueba.PersonaRow;

now the variable call prueba have the information of the row mapping exactly like the database table but in a object that i can manipulate like this现在变量调用prueba具有与数据库表完全相同的行映射信息,但在 object 中,我可以像这样操作

prueba.Cedula prueba.Nombre prueba.Cedula prueba.Nombre

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM