如何在gridview中显示值 [英] How to show values in gridview

查看:84
本文介绍了如何在gridview中显示值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个表单第一个表单,其中有文本框,显示来自datagridview的值

和第二个表单有datagrideview,当我关闭此表单时第一行显示第一个表单而没有单击双击。 .........我如何解决这个问题



这是我的第一种形式的代码: -

i have 2 form first form that have text boxes that display value from datagridview
and second form have datagrideview when i close this form the first row display in the first form without i click double click .......... how i solve this problem

this is my code in first form :-

private void btn_Browse_Click(object sender, EventArgs e)
{
   try
   {
       FRM_Car_Data_List frm = new FRM_Car_Data_List();
       frm.ShowDialog();
       this.txt_Car_id.Text = frm.dataGridView1.CurrentRow.Cells[0].Value.ToString();
       this.txt_Car_No.Text = frm.dataGridView1.CurrentRow.Cells[1].Value.ToString();
       this.txt_Car_No_2.Text = frm.dataGridView1.CurrentRow.Cells[2].Value.ToString();
       this.txt_Car_shs.Text = frm.dataGridView1.CurrentRow.Cells[3].Value.ToString();
       this.txt_Mator_No.Text = frm.dataGridView1.CurrentRow.Cells[4].Value.ToString();
       this.CB_Car_Type.Text = frm.dataGridView1.CurrentRow.Cells[5].Value.ToString();
       this.CB_ModelCar.Text = frm.dataGridView1.CurrentRow.Cells[6].Value.ToString();
       this.txt_year.Text = frm.dataGridView1.CurrentRow.Cells[7].Value.ToString();
       this.txt_Capecity.Text = frm.dataGridView1.CurrentRow.Cells[8].Value.ToString();
       this.txt_Ton.Text = frm.dataGridView1.CurrentRow.Cells[9].Value.ToString();
       this.CB_Color.Text = frm.dataGridView1.CurrentRow.Cells[10].Value.ToString();
       this.dtp_Date_Bay.Text = frm.dataGridView1.CurrentRow.Cells[11].Value.ToString();
       this.dtp_Date_in.Text = frm.dataGridView1.CurrentRow.Cells[12].Value.ToString();
       this.CB_Owner.SelectedItem = frm.dataGridView1.CurrentRow.Cells[13].Value.ToString();
       this.CB_Place.SelectedItem = frm.dataGridView1.CurrentRow.Cells[14].Value.ToString();
       this.dtp_Car_e_date_licen.Text = frm.dataGridView1.CurrentRow.Cells[15].Value.ToString();
       this.txt_Notes.Text = frm.dataGridView1.CurrentRow.Cells[15].Value.ToString();
       this.txt_Car_id.ReadOnly = true;
       this.txt_Car_No.ReadOnly = true;
       this.txt_Car_No_2.ReadOnly = true;
       this.State = "Show";
       this.txt_Car_id.Focus();
       this.btn_Add.Enabled = false;
       this.btn_Edit.Enabled = true;
       this.btn_Delete.Enabled = true;
       this.btn_NewData.Enabled = true;
   }
   catch
   {
       return;
   }
}



第二种形式是: -


second form is :-

public partial class FRM_Car_Data_List : Form
{
  BL.CLS_CARS_DATA frmCls = new BL.CLS_CARS_DATA();

  public FRM_Car_Data_List()
  {
      InitializeComponent();
      this.dataGridView1.DataSource = frmCls.GET_ALL_CARS_DATA();
  }

  private void dataGridView1_DoubleClick(object sender, EventArgs e)
  {
      this.Close();
  }

  private void txt_Search_Car_Data_TextChanged(object sender, EventArgs e)
  {
      DataTable dt = new DataTable();
      dt = frmCls.Search_Car_Data(txt_Search_Car_Data.Text);
      this.dataGridView1.DataSource = dt;
  }
}

推荐答案

我不能把gotether一个测试应用程序,但我会看当您关闭表单时,CurrentRow会发生什么。如果DGV不再可见,查看CurrentRow是否回到第一行。
I can't put gotether a test app, but I'd be looking at what happens to "CurrentRow" when you close the form. See if the "CurrentRow" goes back to the first row if the DGV is no longer visible.


这篇关于如何在gridview中显示值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆