associate tabcontrol tab with string

65 Views Asked by At

I have an application that uses a TabControl to hold a RichTextBox. The user has the ability to open more tabs as they wish.

I need a way to associate each tab with a string, so that I can store the filepaths for saving.

To clarify, When opening a file in a new tab, I need to be able to store the string with the tab. In Java, I would use a HashMap<Tab, String> to solve this problem.

Is there a way to solve this problem?

Thank you in advance

2

There are 2 best solutions below

0
On BEST ANSWER

You can use Dictionary<Tab, String>. More information can be found here

0
On

You can assign the string to the Tag property of each tab. You'll need to cast from object when using it, but that's the easiest/most efficient way. This property is available on all controls (both windows forms and WPF I believe) for associating objects in the exactly the way you want

As lll suggests, you can also use a Dictionary, which is C#'s equivalent of a hash map.