2010-11-18 7 views
3

GTK #에서 트리 뷰의 선택한 항목을 가져 오는 방법을 이해할 수 없습니다. 내 코드 예제 : 여기에, 내가 선택한 행을 얻을 수있는 방법, 을 OnTvstockRowActivated 내에서 Gtk # 및 treeview : "선택한"항목을 얻는 방법?

 Gtk.TreeViewColumn marketCol = new Gtk.TreeViewColumn(); 
      marketCol.Title = "Market"; 

      tvstock.AppendColumn(marketCol); 

      Gtk.TreeIter iter = stockListStore.AppendValues ("Dax30");  

      stockListStore.AppendValues(iter, "Adidas"); 
      stockListStore.AppendValues(iter, "Commerzbank"); 

      iter = stockListStore.AppendValues ("Cac40");  
      stockListStore.AppendValues(iter, "Bnp Paribas"); 
      stockListStore.AppendValues(iter, "Veolia"); 

      iter = stockListStore.AppendValues ("FtseMib");  
      stockListStore.AppendValues(iter, "Fiat"); 
      stockListStore.AppendValues(iter, "Unicredit"); 

      tvstock.Model = stockListStore; 

      // Create the text cell that will display the artist name 
      Gtk.CellRendererText marketNameCell = new Gtk.CellRendererText(); 
      // Add the cell to the column 
      marketCol.PackStart (marketNameCell, true);  

      // Tell the Cell Renderers which items in the model to display 
      marketCol.AddAttribute (marketNameCell, "text", 0);   

tvStock

에 데이터를로드? 감사합니다.

답변

5

args에 행의 경로가 있습니다.이 행에서 iter를 생성 할 수 있습니다.

protected virtual void OnTvstockRowActivated (object o, Gtk.RowActivatedArgs args) 
{ 
    var model = tvstock.Model; 
    TreeIter iter; 
    model.GetIter (out iter, args.Path); 
    var value = model.GetValue (iter, 0); 
    Console.WriteLine (value); 
}