I know how to pull data from a db and present it in a textbox in a form

my question is, how can i pull data from a db and present it in a datagridview?

and another thing,

once a certain row is double clicked, new form will show and a data will be sent to that ready to be edited.

Thanks!

Can u explain little bit more it's hard to understand

hi
to display your data in gridview without any modyfication you can go for datareader or go for adapter to fill the data and bind it to gridview using datasource

con.Open();
            cmd.Connection = con;
            SqlDataAdapter da = new SqlDataAdapter("select * from tablename ", con);
            DataSet ds = new DataSet();
            da.Fill(ds, "Tablename");
         gridviewname.DataSource = ds.Tables["tablename"];
            con.Close();

for the secound question double click your gridview and pass event ..in that send the value to a new form as required .

hope this would help you.

Thanks! how to get the row value of the selected gridview record then?

where do you want to display the selected value from the gridview
..is it to individual controls or in a new form .

Im planning to add a new form or i can just simply add textboxes on the same form.

what i want to know though is the method name if a certain row in a datagrid view is selected?

and event name for double clicking the selected row so i can pass in the records to a new form?

by the way. is there a chance to disable the cursor from displaying in the datagrid view once record is clicked? or act as a read only to avoid the conception of being able to edit a record.

and one more thing, how to add one row at the bottom of the datagrid?

so many questions!

Thanks for the prompt answer mate!

try this ...one way to select the row data to respective controls

private void dataGridView1_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            listBox1.Items.Clear();
            textBox1.Text = this.dataGridView1.CurrentRow.Cells[0].Value.ToString();
            textBox2.Text = this.dataGridView1.CurrentRow.Cells[1].Value.ToString();
            textBox3.Text = this.dataGridView1.CurrentRow.Cells[2].Value.ToString();
            comboBox2.Text = this.dataGridView1.CurrentRow.Cells[3].Value.ToString();
            textBox5.Text = this.dataGridView1.CurrentRow.Cells[4].Value.ToString();
            //maskedTextBox1.Text = this.dataGridView1.CurrentRow.Cells[5].Value.ToString();
            textBox7.Text = this.dataGridView1.CurrentRow.Cells[6].Value.ToString();
            textBox8.Text = this.dataGridView1.CurrentRow.Cells[7].Value.ToString();
            comboBox1.Text = this.dataGridView1.CurrentRow.Cells[8].Value.ToString();
           

        }

i see what you got. thanks!

never mind the event name, i got it!

my question then are:

getting the primary key of the selected row?

thanks!

and

do not allow editing on the cell

hi..
primary key will be your column name so call that column particularly, secondly go for read only property to avoid editing data grid.

I figured out whats the event name

I figured out how to disable cursor

I figured out how to read only

last question: whats the code to fetch the record by selected datagrid row?

thanks!

mark this as solved since I got all i need from the web. thanks!

Hi..
the above code will help you to fetch the selected record in controls using gridview click event ..
Can you be precise in your question please.

I figured it out using rouheader click event. thanks for your prompt reply!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.