Click here to Skip to main content
15,887,344 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
my windows form (form1) has textbox control (textbox1) , combobox control (combobox1) which all contain items (table1 - table2 - table3) and the sql database name (database1) and it has a tables (table1 - table2 - table3)which are identical each contains columns (itemcode - itemname - itemprice)

i want to show the last row of column(itemcode) according to table name i will choose from combobox1

how to do that in code and in which event of the controls please
Posted
Updated 16-Oct-15 6:02am
v2
Comments
Maciej Los 16-Oct-15 12:36pm    
What have you triedtill now? Where are you stuck?
Ahmed Zoeil 16-Oct-15 12:52pm    
I still can't figure yet how to do it
Ahmed Zoeil 16-Oct-15 13:35pm    
I really need your help
Maciej Los 16-Oct-15 15:10pm    
"i want to show the last row of itemcode" - can you elaborate what you mean?
ChrisCreateBoss 16-Oct-15 20:37pm    
With table are you refering to a DataGridView control or a DataTable?

Please try some thing like this
C#
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
    Control[] ctrl = this.Controls.Find(comboBox1.SelectedItem.ToString(),true);

    if (ctrl.Length > 0)
    {
         DataGridView dgv = (DataGridView)ctrl[0];

         textBox1.Text = dgv.Rows[dgv.Rows.Count - 1].Cells[0].Value.ToString();
    }
        
}
 
Share this answer
 
select top 1 from "+dropdownlist1.selecteditem.text+" order by itemcode desc
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900