Results 1 to 6 of 6

Thread: Help formating & filtering dgv or DS

  1. #1

    Thread Starter
    Fanatic Member Crash893's Avatar
    Join Date
    Dec 2005
    Posts
    930

    Help formating & filtering dgv or DS

    Hi all

    I am passing a dataset to a dgv and i need to add a column to the DGV that is not in the dataset but is made from info in the dataset

    example

    col1
    12
    34
    14
    47

    col0(<-add) col1
    hyperlink12 12
    hyperlink34 34
    hyperlink14 14
    hyperlink47 47


    I also want to go through certain column's and remove some text

    companyname/user
    companyname/user2

    to just:
    user
    user2


    then the last thing i want to do is filter feilds by date or other criteria



    So my question is

    should i do this at the data table level or should i do it at the data grid level because i'm not sure i want to mess with the original data just yet

    then depending on where i edit the data does anyone have a good example that i could look at to point me in the right direction?

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

    Re: Help formating & filtering dgv or DS

    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 Crash893's Avatar
    Join Date
    Dec 2005
    Posts
    930

    Re: Help formating & filtering dgv or DS

    Just incase anyone wants to see

    vb Code:
    1. private void CreateUnboundButtonColumn()
    2. {
    3.     // Initialize the button column.
    4.     DataGridViewButtonColumn buttonColumn =
    5.         new DataGridViewButtonColumn();
    6.     buttonColumn.Name = "Details";
    7.     buttonColumn.HeaderText = "Details";
    8.     buttonColumn.Text = "View Details";
    9.  
    10.     // Use the Text property for the button text for all cells rather
    11.     // than using each cell's value as the text for its own button.
    12.     buttonColumn.UseColumnTextForButtonValue = true;
    13.  
    14.     // Add the button column to the control.
    15.     dataGridView1.Columns.Insert(1, buttonColumn);
    16. }

  4. #4

    Thread Starter
    Fanatic Member Crash893's Avatar
    Join Date
    Dec 2005
    Posts
    930

    Re: Help formating & filtering dgv or DS

    3 left over questions

    1) what is the event for when i click on one of the new buttons i have created
    here is what i have but i dont think im even close

    c# Code:
    1. private void dataGridView1_CellClick(object sender,DataGridViewCellEventArgs e)
    2.         {
    3.  
    4.             MessageBox.Show("hi you pushed a button");
    5.         }

    2) to edit and format the data do i do it at the datagridview level or at the Dataset/datatable level?


    3) Probably related to 2 but how is filtering done with DGV?

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

    Re: Help formating & filtering dgv or DS

    1. CellContentClick.

    2. You should bind your data to a BindingSource and then bind that to the control(s). All manipulation of data in code should then be done via the BindingSource.

    3. Set the Filter property of the BindingSource. If you don't use a BindingSource then you'd set the DefaultView.RowFilter property of the DataTable but I can't recommend strongly enough that you use a BindingSource.
    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

  6. #6

    Thread Starter
    Fanatic Member Crash893's Avatar
    Join Date
    Dec 2005
    Posts
    930

    Re: Help formating & filtering dgv or DS

    Here is what i go so far it seems to be working pretty well
    but i still need to test with a few filters strung together (i will Google it)

    c# Code:
    1. BindingSource gridinfo = new BindingSource();
    2.        
    3.         private void button2_Click(object sender, EventArgs e)
    4.         {
    5.             //create new Dataset named DS
    6.             DataSet DS = new DataSet();
    7.             // Query string that we can Manupulate later
    8.             string query = "SELECT gci_requests.id, gci_requests.ref_num, gci_requests.summary, gci_requests.description, gci_requests.open_date, gci_requests.last_modified_date, gci_requests.close_date, gci_requests.resolve_date, gci_requests.status, gci_requests.rootcause, gci_requests.priority, gci_requests.urgency, gci_requests.problem, gci_requests.type, gci_requests.category_name, gci_requests.assignee_adaccount, gci_requests.reportedby_adaccount, gci_requests.customer_adaccount, gci_requests.group_name FROM mdb_rpt.dbo.gci_requests gci_requests WHERE gci_requests.group_name='" + comboBox1.Text + "'";
    9.             //sending Dataset , query and tablename to the sub TEST
    10.             Test(query, DS, "gci_requests");
    11.            //binding the Dataset to the binding source
    12.             gridinfo.DataSource = DS;
    13.             gridinfo.DataMember = "gci_requests";
    14.             //useing the binding source to populate the datagridview            
    15.             dataGridView1.DataSource = gridinfo;
    16.  
    17. private void Form1_Load(object sender, EventArgs e)
    18.         {
    19.             comboBox1.Items.Add("USAT-Publishing Solutions");
    20.             comboBox1.Items.Add("USAT-Operations");
    21.             comboBox1.Items.Add("USAT-Desktop");
    22.             comboBox1.Text = "USAT-Publishing Solutions";
    23.            
    24.            
    25.             comboBox2.Items.Add("502212");
    26.             comboBox2.Items.Add("502213");
    27.             comboBox2.Items.Add("502214");
    28.             comboBox2.Items.Add("502215");
    29.             comboBox2.Items.Add("502216");
    30.             comboBox2.Items.Add("");
    31.             comboBox2.Text = "";
    32.  
    33.            
    34.         }
    35.  
    36.         private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
    37.         {
    38.             if (comboBox2.Text != "")
    39.             {
    40.                 gridinfo.Filter = "rootcause = '" + comboBox2.Text + "'";
    41.             }
    42.             else
    43.             {
    44.                 gridinfo.Filter = "";
    45.             }
    46.  
    47.            
    48.         }

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