2012-09-09 5 views
1

XtragridControl gridview에서 선택한 행의 그림이나 이미지를 양식의 그림 상자로 검색하는 방법에 대한 다른 적절한 방법을 찾고 싶습니다.선택한 GridView 행에서 이미지를 검색하는 방법

이것은 시나리오입니다.

리본 컨트롤이 여러 버튼으로 구성되어 있으며, 첫 번째 버튼은 고객 데이터를 엽니 다. 두 버튼으로 고객 컨트롤을 찾습니다. 첫 번째 버튼은 고객 양식을 열어 새로운 고객을 추가하고 두 번째 버튼은 고객 편집 폼을 엽니 다. 그리드에서 특정 고객을 선택한 후 고객을 편집하는 경우 다른 모든 정보와 함께 고객의 이미지 나 사진을 검색 할 수있는보다 간단한 방법을 원합니다.

내 코드의 예를 보자 :

// this my class Holding Field from table in database 

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.IO; 
using System.Drawing; 

    namespace YoungWoman 
    { 
     public static class GetRowData 
     {  

    public static int LesseeId; 

    public static byte image; // 



    public static string LesseeName; 
    public static string LesseeLastName; 
    public static string PassportNo; 
    public static string IDNo; 
    public static DateTime BirthDate; 
    public static string Gender; 
    public static string Country; 
    public static string City; 
    public static string Province; 
    public static string LesseePostalCode; 
    public static string MobileNo; 
    public static string HomePhoneNo; 
    public static string TutorName; 
    public static string TutorLastName; 
    public static string AddressTutor; 
    public static string AddressLessee; 
    public static string TutorPhoneNo; 
    public static string TutorEmail; 




    } 
    } 


    // this user control containing the XtragridControl and how i retrieve values from the grid to get the form populated 


     private void EditLesseeFrm_Click(object sender, EventArgs e) 
    { 
     Lesseefrm Lessee = new Lesseefrm(Utils.Formtype.edit, 1); 
     Lessee.LesseeEventHandler += new EventHandler(RefreshLesseeGrid); 
     Lessee.RefreshLabeslEvent += new EventHandler(RefreshingLabels); 


     GetRowData.LesseeId = Convert.ToInt32(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "LesseeId")); 
     //GetRowData.LesseePic = ByteImageConve(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "LesseePic")); // this line of code return an error 
     GetRowData.LesseeName = Convert.ToString(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "LesseeName")); 
     GetRowData.LesseeLastName = Convert.ToString(gridView1.GetRowCellValue(gridView1.FocusedRowHandle,"LesseeLastName")); 
     GetRowData.PassportNo = Convert.ToString(gridView1.GetRowCellValue(gridView1.FocusedRowHandle,"PassportNo")); 
     GetRowData.Gender = Convert.ToString(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Gender")); 
     GetRowData.Province = Convert.ToString(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Province")); 
     GetRowData.BirthDate = Convert.ToDateTime(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "BirthDate")); 
     GetRowData.City = Convert.ToString(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "City")); 
     GetRowData.Country = Convert.ToString(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Country")); 
     GetRowData.MobileNo = Convert.ToString(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "MobileNo")); 
     GetRowData.HomePhoneNo = Convert.ToString(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "HomePhoneNo")); 
     GetRowData.IDNo = Convert.ToString(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "IDNo")); 
     GetRowData.AddressLessee = Convert.ToString(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "AddressLessee")); 
     GetRowData.AddressTutor = Convert.ToString(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "AddressTutor")); 
     GetRowData.LesseePostalCode = Convert.ToString(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "LesseePostalCode")); 
     GetRowData.TutorName = Convert.ToString(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TutorName")); 
     GetRowData.TutorLastName = Convert.ToString(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TutorLastName")); 
     GetRowData.TutorPhoneNo = Convert.ToString(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TutorPhoneNo")); 
     GetRowData.TutorEmail = Convert.ToString(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TutorEmail")); 

     Lessee.ShowDialog(); 
    } 


     // this the form to receive the values from the grid to update 



      if (formtype == Formtype.edit && Lesseeid > 0) 
      { 



       LesseeIdtextEdit.Enabled = false; 
       ClearBtnlayoutControlItem26.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never; 
       SaveBtn.Text = "&Edit"; 
       SaveBtn.Image = Resources.brush_16; 
       this.Text = string.Format(" Edit Lessee Information - YW Residence "); 

       LesseeIdtextEdit.Text = Convert.ToInt32(GetRowData.LesseeId).ToString(); 
       txtName.Text = GetRowData.LesseeName; 
       txtLAstname.Text = GetRowData.LesseeLastName; 
       txtPassport.Text = GetRowData.PassportNo; 
       txtID.Text = GetRowData.IDNo; 
       GendercomboBoxEdit.SelectedItem = GetRowData.Gender; 
       DobdateEdit.DateTime = GetRowData.BirthDate; 
       CountrycomboBoxEdit.SelectedItem = GetRowData.Country; 
       txtProvince.Text = GetRowData.Province; 
       txtCity.Text = GetRowData.City; 
       txtPostalCode.Text = GetRowData.LesseePostalCode; 
       LesseememoEdit1.Text = GetRowData.AddressLessee; 
       txtMobile.Text = GetRowData.MobileNo; 
       txtHomePhone.Text = GetRowData.HomePhoneNo; 
       txtTutorName.Text = GetRowData.TutorName; 
       txttutorLastname.Text = GetRowData.TutorLastName; 
       tutorAddresstxt.Text = GetRowData.AddressTutor; 
       txtTutorMobile.Text = GetRowData.TutorPhoneNo; 
       txtEmail.Text = GetRowData.TutorEmail; 



      } 


     and this how i save before proceeding to any update 



      private void SaveBtn_Click(object sender, EventArgs e) 
    { 

     if (formtype == Formtype.add) 
     { 
      if (txtPassport.Text.Length >= 8) 
      { 
       dxErrorProvider1.ClearErrors(); 



       try 
       { 

        MemoryStream ms = new MemoryStream(); 
        PicBox1.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); 
        byte[] Pic_arr = new byte[ms.Length]; 
        ms.Position = 0; 
        ms.Read(Pic_arr, 0, Pic_arr.Length); 

        da.InsertCommand = new SqlCommand(" insert into LesseeYW (LesseePic,LesseeName,LesseeLastName,PassportNo,IDNo,BirthDate,Gender,Country,LesseePostalCode,City,Province,MobileNo,HomePhoneNo,TutorName,TutorLastName,AddressTutor,AddressLessee,TutorPhoneNo,TutorEmail)Values(@image1,@name,@LastName,@pass1,@IDno,@DOB,@Gender,@Country1,@Postal,@City,@Province,@Mobile,@Phone,@Tname,@TLast,@address1,@address2,@Tphone,@Email)", conne); 
        da.InsertCommand.Parameters.AddWithValue("@id", GetRowData.LesseeId); 
        da.InsertCommand.Parameters.AddWithValue("@image1", Pic_arr); 
        da.InsertCommand.Parameters.AddWithValue("@name", txtName.Text); 
        da.InsertCommand.Parameters.AddWithValue("@LastName", txtLAstname.Text); 
        da.InsertCommand.Parameters.AddWithValue("@pass1", txtPassport.Text); 
        da.InsertCommand.Parameters.AddWithValue("@IDno", txtID.Text); 
        da.InsertCommand.Parameters.AddWithValue("@DOB", DobdateEdit.DateTime); 
        da.InsertCommand.Parameters.AddWithValue("@Gender", GendercomboBoxEdit.SelectedItem.ToString()); 
        da.InsertCommand.Parameters.AddWithValue("@Country1", CountrycomboBoxEdit.SelectedItem.ToString()); 
        da.InsertCommand.Parameters.AddWithValue("@Postal", txtPostalCode.Text); 
        da.InsertCommand.Parameters.AddWithValue("@City", txtCity.Text); 
        da.InsertCommand.Parameters.AddWithValue("@Province", txtProvince.Text); 
        da.InsertCommand.Parameters.AddWithValue("@Mobile", txtMobile.Text); 
        da.InsertCommand.Parameters.AddWithValue("@Phone", txtHomePhone.Text); 
        da.InsertCommand.Parameters.AddWithValue("@Tname", txtTutorName.Text); 
        da.InsertCommand.Parameters.AddWithValue("@TLast", txttutorLastname.Text); 
        da.InsertCommand.Parameters.AddWithValue("@address1", tutorAddresstxt.Text); 
        da.InsertCommand.Parameters.AddWithValue("@address2", LesseememoEdit1.Text); 
        da.InsertCommand.Parameters.AddWithValue("@Tphone", txtTutorMobile.Text); 
        da.InsertCommand.Parameters.AddWithValue("@Email", txtEmail.Text); 


        da.InsertCommand.ExecuteNonQuery(); 
        conne.Close(); 
        MessageBox.Show(" Lessee Data Successfully Added ", " Confirmation Lessee Data ", MessageBoxButtons.OK, MessageBoxIcon.Information); 
        this.Close(); 
       } 

       catch (Exception Ex) 
       { 
        MessageBox.Show(Ex.Message); 
       } 
      } 

      else 
      { 
       MessageBox.Show("Invalid PassportNo","Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); 
       dxErrorProvider1.SetError(txtPassport, "Invalid Passport No"); 

      } 


      if (LesseeEventHandler != null) 
      { 
       LesseeEventHandler(sender, e); 
      } 

      if (LsEventHandler != null) 
      { 
       LsEventHandler(sender, e); 
      } 

      if (SelectEventHandler != null) 
      { 
       SelectEventHandler(sender, e); 
      } 
      if (LabelsEvent != null) 
      { 
       LabelsEvent(sender, e); 
      } 


     } 

답변

0

나는 그리드에 테이블의 내용을 결합하는, 강력하게 형식화 된 데이터 집합 또는 EF를 사용합니다. 그러면 데이터를로드하고 저장하는 것에 대해 그렇게 생각할 필요가 없습니다.

devexpress를 사용하고 있으므로 DataLayoutControl을 사용하여 데이터 소스의 다른 필드를 바인딩합니다.

이미지를 바이트로 선언 했으니까요? 바이트 [] 또는 이미지 사용

클래스를 사용하려면 변수를 속성으로 바꾼 다음 gui 컨트롤에 바인딩하고 클래스의 속성을 사용하는 것이 좋습니다.

관련 문제