2009-06-02 1 views
0

私はこのようになり、従業員のデータ入力フォームを構築しようとしています:.NET 3.5でDataGridViewを使用するにはどうすればよいですか?

 
Employee Form 
----------------------------------------------- 
---------------------------------------  | 
|   | Name  |   |  | 
| Picture | Department |   |  | 
|   | Position |   |  | 
|   | DOB  |   |  | 
---------------------------------------  | 
... repeat for every employee     | 
...           | 
---------------------------------------  | 
|   | Name  |   |  | 
| Picture | Department |   |  | 
|   | Position |   |  | 
|   | DOB  |   |  | 
---------------------------------------  | 
----------------------------------------------- 

これは、Microsoft Accessでこれを構築することは非常に簡単ですが、どのように私はそれがC#+ .NET 3.5 + Winformsのを使用して構築することができますか?
私はDataGridViewを使用しようとしましたが、上の例のようには見えませんでした。

+0

極端に悲しい顔。私は今あなたの質問に答えることはできませんが、私はあなたのVB.netを使って話すことを正確に作成しました。私がラップトップに帰ると、ここに着いてコードを貼り付けて、一度走ったように見える画像を投稿しようとします。唯一のことはわかりませんが、私はDataGridViewの代わりにlistViewを使用した可能性があります。 – Bryan

答えて

-3

リピータにデータをバインドしてみませんか?

<asp:Repeater ID="Repeater1" runat="server"> 
    <HeaderTemplate> 
     <table> 
    </HeaderTemplate> 
    <ItemTemplate> 
     <tr> 
      <td rowspan="4"> 
       <%# Eval("Picture") %> 
      </td> 
      <td> 
       <%# Eval("Name") %> 
      </td> 
     </tr> 
     <tr> 
      <td> 
       <%# Eval("Department") %> 
      </td> 
     </tr> 
     <tr> 
      <td> 
       <%# Eval("Position") %> 
      </td> 
     </tr> 
     <tr> 
      <td> 
       <%# Eval("DOB") %> 
      </td> 
     </tr> 
    </tr> 
</ItemTemplate> 
<FooterTemplate> 
    </table></FooterTemplate> 
</asp:Repeater> 
+0

WebFormsに最適です。 WinFormsではあまり役に立ちません。 –

+0

OK私の悪い私は十分にそれを十分に読んでいない。 –

+0

ありがとう、私はDataRepeaterに付属のMicrosoft Visual Basic Power Packs 3.0を使用しています。 リピータ内の要素を列挙する方法に悩まされています。 MicrosoftがDataRepeaterの子どもたちに簡単にアクセスできるのはなぜですか? – portoalet

0

FlowLayoutPanelまたは類似した何かに、そのコントロールの複数のインスタンスを追加し、その後、単一の従業員のために、すべてのデータが含まれているカスタムコントロールを構築してみます。カスタムコントロールは、ピクチャボックスといくつかのテキストボックスを含む分割されたパネルで簡単に操作できます。

1

私はついにラップトップを持って帰ってきました。だから、あなたがやりたいことと同じことをやったのは、私がListViewを使って、データテーブルから動的に記入することです。ここでは、コード(私がやっている内容の要約は、コードの後下部にあるようです)です:

For i = 0 To frmSelection.MechDataTable2.Rows.Count - 1 
      Dim tmpGroup As ListViewGroup = New ListViewGroup(frmSelection.MechDataTable2.Rows(i).Item("MechName")) 
      ltvMechs.Groups.Add(tmpGroup) 
      Dim tmpListItem1 As ListViewItem = New ListViewItem(tmpGroup) 
      Dim tmpListItem2 As ListViewItem = New ListViewItem(tmpGroup) 
      Dim tmpListItem3 As ListViewItem = New ListViewItem(tmpGroup) 
      Dim tmpListItem4 As ListViewItem = New ListViewItem(tmpGroup) 
      Dim tmpListItem5 As ListViewItem = New ListViewItem(tmpGroup) 

      'row1 
      tmpListItem1.SubItems.Add("co1") 
      tmpListItem1.SubItems.Add("co2") 
      tmpListItem1.SubItems.Add("co3") 
      tmpListItem1.SubItems.Add("co4") 
      tmpListItem1.SubItems.Add("co5") 
      tmpListItem1.SubItems.Add("co6") 
      tmpListItem1.SubItems.Add("co7") 

      tmpListItem1.SubItems(0).Text = "Select" 
      tmpListItem1.SubItems(1).Text = frmSelection.MechDataTable2.Rows(i).Item("Price") 
      tmpListItem1.SubItems(2).Text = frmSelection.MechDataTable2.Rows(i).Item("MechID") 
      tmpListItem1.SubItems(3).Text = "Faction Orientation" 
      tmpListItem1.SubItems(4).Text = frmSelection.MechDataTable2.Rows(i).Item("FactionOrientation") 
      tmpListItem1.SubItems(5).Text = "Engine HDP" 
      tmpListItem1.SubItems(6).Text = frmSelection.MechDataTable2.Rows(i).Item("EngineHardPoint") 


      'row2 
      tmpListItem2.SubItems.Add("co1") 
      tmpListItem2.SubItems.Add("co2") 
      tmpListItem2.SubItems.Add("co3") 
      tmpListItem2.SubItems.Add("co4") 
      tmpListItem2.SubItems.Add("co5") 
      tmpListItem2.SubItems.Add("co6") 
      tmpListItem2.SubItems.Add("co7") 

      tmpListItem2.SubItems(0).Text = "" 
      tmpListItem2.SubItems(1).Text = "" 
      tmpListItem2.SubItems(2).Text = "" 
      tmpListItem2.SubItems(3).Text = "Required Rep" 
      tmpListItem2.SubItems(4).Text = frmSelection.MechDataTable2.Rows(i).Item("RequiredRep") 
      tmpListItem2.SubItems(5).Text = "Generator HDP" 
      tmpListItem2.SubItems(6).Text = frmSelection.MechDataTable2.Rows(i).Item("GeneratorHardPoint") 


      'row3 
      tmpListItem3.SubItems.Add("co1") 
      tmpListItem3.SubItems.Add("co2") 
      tmpListItem3.SubItems.Add("co3") 
      tmpListItem3.SubItems.Add("co4") 
      tmpListItem3.SubItems.Add("co5") 
      tmpListItem3.SubItems.Add("co6") 
      tmpListItem3.SubItems.Add("co7") 

      tmpListItem3.SubItems(0).Text = "" 
      tmpListItem3.SubItems(1).Text = "" 
      tmpListItem3.SubItems(2).Text = "" 
      tmpListItem3.SubItems(3).Text = "Resilience" 
      tmpListItem3.SubItems(4).Text = frmSelection.MechDataTable2.Rows(i).Item("Resilience") 
      tmpListItem3.SubItems(5).Text = "Heavy HDP" 
      tmpListItem3.SubItems(6).Text = frmSelection.MechDataTable2.Rows(i).Item("HeavyHardPoint") 


      'row4 
      tmpListItem4.SubItems.Add("co1") 
      tmpListItem4.SubItems.Add("co2") 
      tmpListItem4.SubItems.Add("co3") 
      tmpListItem4.SubItems.Add("co4") 
      tmpListItem4.SubItems.Add("co5") 
      tmpListItem4.SubItems.Add("co6") 
      tmpListItem4.SubItems.Add("co7") 

      tmpListItem4.SubItems(0).Text = "" 
      tmpListItem4.SubItems(1).Text = "" 
      tmpListItem4.SubItems(2).Text = "" 
      tmpListItem4.SubItems(3).Text = "Weight" 
      tmpListItem4.SubItems(4).Text = frmSelection.MechDataTable2.Rows(i).Item("Weight") 
      tmpListItem4.SubItems(5).Text = "Medium HDP" 
      tmpListItem4.SubItems(6).Text = frmSelection.MechDataTable2.Rows(i).Item("MediumHardPoint") 


      'row5 
      tmpListItem5.SubItems.Add("co1") 
      tmpListItem5.SubItems.Add("co2") 
      tmpListItem5.SubItems.Add("co3") 
      tmpListItem5.SubItems.Add("co4") 
      tmpListItem5.SubItems.Add("co5") 
      tmpListItem5.SubItems.Add("co6") 
      tmpListItem5.SubItems.Add("co7") 

      tmpListItem5.SubItems(0).Text = "" 
      tmpListItem5.SubItems(1).Text = "" 
      tmpListItem5.SubItems(2).Text = "" 
      tmpListItem5.SubItems(3).Text = "Structure" 
      tmpListItem5.SubItems(4).Text = frmSelection.MechDataTable2.Rows(i).Item("Class") 
      tmpListItem5.SubItems(5).Text = "Light HDP" 
      tmpListItem5.SubItems(6).Text = frmSelection.MechDataTable2.Rows(i).Item("LightHardPoint") 


      ltvMechs.Items.Add(tmpListItem1) 
      ltvMechs.Items.Add(tmpListItem2) 
      ltvMechs.Items.Add(tmpListItem3) 
      ltvMechs.Items.Add(tmpListItem4) 
      ltvMechs.Items.Add(tmpListItem5) 
     Next 

基本的には、各リスト項目は、グループ内の行で、各下位項目は(行のセルでありますあなたがExcelに見られるものに似ています、アクセス法。)サブアイテム(0)はcol1にあり、サブアイテム(1)はcol2にあります。あなたの最初の列については、listItem1の下位項目(0)を画像にし、他の下位項目(0)のすべてを空白にします。私は上記の私のコメントを言ったように、私はvb.netでこれをコード化しましたが、私がそれを見たすべてのアカウントではC#とはそれほど違いはありません。また、このコードが作り出すものの一部の写真もあります。品質のため申し訳ありませんが、それは私が仕事をしなければならなかったことでできる最善のことです。 alt text http://img268.imageshack.us/img268/7977/listviewexample.png

0

まず、BindingListViewを取得します。次に、DataTable/Setsを使用するのではなく、List <T>をDataGridViewsにバインドできます。次のように、2番目の列のDataPropertyNameに「詳細」プロパティを設定できます。

public string Details 
{ 
    get 
    { 
     return string.Format("{0}\n{1}\n{2}\n{3}", Name, Department, Position, DOB); 
    } 
}