Solved

Textbox in Form2 shows information from DataGridView in Form1

Posted on 2006-11-30
5
1,292 Views
Last Modified: 2012-06-22
I figured this would be super simple but im having a hard time finding anything on google.

Basically I have a datagridview on Form1. This datagridview shows columns 1 through 3 (lets say there is a 10 datacolumns).
I want to be able to click on the row of the datagridview, display Form2, have 10 textbox's show the information that is bound in formA. and then eventually just update all the information / save.

Basically form1 = gridview, form2 = detailsview.

the datagridview is being populated from a dataset, that is being populated by an xml file.

Thanks!

0
Comment
Question by:JasonWinn
  • 2
  • 2
5 Comments
 
LVL 5

Expert Comment

by:rameedev
ID: 18051595
What you could do is On click of the datagird row of form1 which has 3 columns (i am assuming you are keeping the Primary Key column as one of the 3 columns)
retreive the PK colimn value do a select from the dataset based on thsi PK get those datarows and use it populate your second grid.
0
 
LVL 3

Author Comment

by:JasonWinn
ID: 18051678
Hi rameedev,

Thank you your response. Thats exactly what I had in mind, my troubles are finding the code for selecting the dataset based on the pk. And instead of "populating" a 2nd grid, I am just trying to populate a 2nd form containing textbox's. Written below is what I am trying to do, just trying to find the right code for it is what is killing me!

the psuedo code:

//form 1
on click datagridview (form 1)
string row and value's
form2.showdialog

//form2
textbox1.text = value's from datagridview / dataset on form1
textbox2.text = .... // ect various textbox's and controls
change text or update value's of textbox
send new information back to the dataset

0
 
LVL 5

Accepted Solution

by:
rameedev earned 250 total points
ID: 18051921
//form1
on the click event of datagrid
you can get the current rownumber and you can hardcode the column number to retreive the PK columns value...put something like this in your datagrid click event

private void dtGrd_Click(object sender, System.EventArgs e)
{
   object cellvalue = dtGrdEmployee[dtGrdEmployee.CurrentRowIndex,0];
   
   //using this cell value as pk retreive data from your dataset..something like this
   DataSet ds = (DataSet)dtGrd.DataSource;
   DataRow[] drArr = ds.Tables[0].Select("PKColumn = '"+ cellvalue +"'");

    string strTxtBox1 = "";
    string strTxtBox2 = "";
    string strTxtBox3 = ""; ///add similar for the No of txtboxes you have in 2nd form

    foreach(DataRow drTmp in drArr)
    {
      strTxtBox1 = drTmp["col1"];
      strTxtBox2 = drTmp["col2"];
      strTxtBox3 = drTmp["col3"];
                ....take all value and assign it to the variables
    }

    //In your form2 overload the constructor to have 10 string arguments
    so when you open the form it can assign the values obtained above directly to it's txtbox
    Form2 objFrm2 =  new Form2("Pass all the values here...strTxtBox1 ,strTxtBox2....and so on")
   
}

//Form2
overloaded Constrcutor
public Form2(string strtxt1,string strtxt2...and so on till whatever values you need)
{
    //after InitializeComponent call
    this.txtbox1.text = strtxt1;
    this.txtbox2.text = strtxt2;
}



0
 
LVL 3

Assisted Solution

by:bromose
bromose earned 250 total points
ID: 18051955
Hi

It can bed done with very littel coding (infact you just have to define some bindings):

If you use a BindingSource, and bind both your datagrid and your textfields to the same instance of BindingSource (make the DataBinding object in form1 and parse it to form2), you will automatic get them in sync.

Then save the dataset to disk.

Hope this helps

Best regards,
Kaj Bromose
0
 
LVL 3

Author Comment

by:JasonWinn
ID: 18065323
Thank you both for you the help. I am splitting the points because each answers the original question but in different ways.

Sort of related question, I am having some problems filtering with a date string, any help on this would be appreciated it:

http://www.experts-exchange.com/Programming/Programming_Languages/C_Sharp/Q_22074261.html
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now