Results 1 to 5 of 5

Thread: datagridview columns inquiry

  1. #1

    Thread Starter
    Fanatic Member popskie's Avatar
    Join Date
    Jul 2005
    Location
    In my chair
    Posts
    666

    datagridview columns inquiry

    hi,
    im new to vs2005. Is this posible to resize the columns and im using c#? 2nd question is how to make a eventhandler of my button inside the columns?
    Code:
    dataset ds = new dataset();					            
    MySqlDataAdapter myadapter =	new MySqlDataAdapter();
    myadapter.SelectCommand = new MySqlCommand();
    myadapter.SelectCommand.Connection  = stsqcon.getConnection();
    myadapter.SelectCommand.CommandText = " Select * from ....";
    myadapter.SelectCommand.Parameters.Add("?veh_code",MySqlDbType.Int32 ,4);
    myadapter.SelectCommand.Parameters["?veh_code"].Value = lv1.SelectedItems[0].SubItems[1].Text;
    myadapter.Fill(ds,"element1");
    datagridview1.DataSource = ds;
    datagridview1.DataMember = "element1";
    Thanks,
    Popskie

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: datagridview columns inquiry

    The DataGridView has a Columns property, and each DataGridViewColumn in the collection has a Width property. I don't know about the Buttons, but they are just regular Button objects so I guess you could go through the Controls property of the DataGridView and attach event handlers to each Button. There may well be a better way than that though.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Fanatic Member popskie's Avatar
    Join Date
    Jul 2005
    Location
    In my chair
    Posts
    666

    Re: datagridview columns inquiry

    Ok thanks jm i try that. But what if i use a datareader,how do i put that data to datagridview.

    thanks,
    Popskie

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: datagridview columns inquiry

    I would say you'd be best to populate a DataTable and bind it, but I'm afraid I'm not really all that familiar with the DataGridView yet.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Fanatic Member popskie's Avatar
    Join Date
    Jul 2005
    Location
    In my chair
    Posts
    666

    Re: datagridview columns inquiry

    Anyone knews how to put data into a datagridbiew using
    datagridview1.Rows.Add();
    thanks in advance

    Popskie

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width