1
Answer

Transferring values between parent and child forms

sanjay  gupta

sanjay gupta

14y
1.8k
1
Dear Sir/Mam

I have two form form1 and form2. on form1 when i press f4 button form2 opens with certain records on datagridview. On clicking of any row of the datagridview that should be filled in form1 textbox after closing the form2. How can i do it? Plz help me soonly.

Thanks 
Sanjay Gupta
Answers (1)
0
Nafihudheen KT

Nafihudheen KT

NA 43 66.6k 13y
Thanks for the replay this is very use full tip, but I have to give the ValueMember as "client_id" because I am saving the combobox selected value, means just saving the "client_id" to the database
0
Vulpes

Vulpes

NA 98.3k 1.5m 13y
If you want to use a standard ComboBox rather than the custom one which Pritish appears to be using, then you'll need to create a List<string> where each item in the List combines the two fields you want to use for a particular row. Something like the following if the ID is always of a constant width:

   List<string> list = new List<string>();

   foreach(DataRow row in dt.Rows)
   {
       list.Add(String.Format("{0} {1}", row["client_id"], row["client_name"]);
   }

   comboName.DataSource = list;
   // no need to set DisplayMember and ValueMember properties  

To get the columns to line up properly, you'll also need to use a fixed-width font such as Consolas.
0
Pritish Deshmukh

Pritish Deshmukh

NA 195 90.5k 13y
protected override void OnDropDown(System.EventArgs e){
Form parent = this.FindForm();
if(this.dataTable != null || this.dataRows!= null){
MultiColumnComboPopup popup = new
MultiColumnComboPopup(this.dataTable,
ref this.selectedRow,columnsToDisplay);
popup.AfterRowSelectEvent+=
new AfterRowSelectEventHandler
(MultiColumnComboBox_AfterSelectEvent);
popup.Location = new Point(parent.Left +
this.Left + 4 ,parent.Top +
this.Bottom + this.Height);
popup.Show();

=====

multiColumnComboBox1.Table = dtable;//DataTable
//Column to display after selection
multiColumnComboBox1.DisplayMember = "Band";
multiColumnComboBox1.ColumnsToDisplay = new
string[]{"Band","Song","Album"};//columns to display
//in the dropdown grid