Отключите или отобразьте узел серым в Редакторе TreeNode

Другой способ сделать это, не используя FasterCSV:

Требуют csv библиотеки рубина в файле инициализатора как config/initializers/dependencies.rb

require "csv"

Как некоторый фон, следующий код базируется прочь Форма Расширенного поиска Ryan Bate , который создает поисковый ресурс. В моем случае выставочный метод поискового ресурса возвратит результаты ранее сохраненного поиска. Это также отвечает на csv и использует шаблон представления для форматирования желаемого вывода.

  def show
    @advertiser_search = AdvertiserSearch.find(params[:id])
    @advertisers = @advertiser_search.search(params[:page])
    respond_to do |format|
      format.html # show.html.erb
      format.csv  # show.csv.erb
    end
  end

show.csv.erb файл похож на следующее:

<%- headers = ["Id", "Name", "Account Number", "Publisher", "Product Name", "Status"] -%>
<%= CSV.generate_line headers %>
<%- @advertiser_search.advertisers.each do |advertiser| -%>
<%- advertiser.subscriptions.each do |subscription| -%>
<%- row = [ advertiser.id,
            advertiser.name,
            advertiser.external_id,
            advertiser.publisher.name,
            publisher_product_name(subscription),
            subscription.state ] -%>
<%=   CSV.generate_line row %>
<%- end -%>
<%- end -%>

На версии HTML страницы отчета у меня есть ссылка для экспорта отчета, что пользователь просматривает. Следующее является link_to, который возвращает csv версию отчета:

<%= link_to "Export Report", formatted_advertiser_search_path(@advertiser_search, :csv) %>

18
задан mr-euro 22 September 2009 в 20:50
поделиться

2 ответа

The TreeNode itself does not have any Enabled property, so you will need to find some means of tracking that state. One way to do this is to create a new class that inherits TreeNode and that features an Enabled property. Another way is to maintain a list of disabled tree nodes.

Once that is done, you can use the ForeColor property of the TreeNode to have it appear grayed out (for instance using the SystemColors.GrayText value).

Finally you can use the BeforeSelect event to evaluate whether it's OK for the user to select a particular node, and use the Cancel property of the event args in that event to prevent selecting it if that node is disabled:

private void TreeView_BeforeSelect(object sender, TreeViewCancelEventArgs e)
{
    e.Cancel = !NodeIsEnabled(e.Node);
}
26
ответ дан 30 November 2019 в 07:39
поделиться

Two options:

  1. Add and remove the nodes on the fly.
  2. Owner draw and handle the clicks and send it to another node.
0
ответ дан 30 November 2019 в 07:39
поделиться
Другие вопросы по тегам:

Похожие вопросы: