ListBox Control Winforms Selected Item Color - Multiple List Box Controls
up vote
1
down vote
favorite
I have 5 list box controls on a single windows form. I'm setting the enabled property to false initially to control read/edit access. This makes it hard to read the selected value without enabling the control. I'm using the enabled property as the ListBox control doesn't have a read-only property like TextBox controls.
I've seen approaches online where I can set
ListBox1.DrawMode = DrawMode.OwnerDrawFixed
And use Draw_Item to control the select item colour.
Private Sub ListBox1_DrawItem(ByVal sender As Object, _ ByVal e As System.Windows.Forms.DrawItemEventArgs) _
However, I've not seen an approach for applying this to multiple ListBox controls on a form. I don't really want to have to tap into Draw_Item for each ListBox.
Also, the ListBox controls are data bound to a DataSet. Anyone had this issue before? If so, how did you handle it?
Or does one know a way of controlling whether a ListBox control is read-only or selectable based on view/edit state?
Thanks in advance for any tips.
vb.net winforms listbox
|
show 4 more comments
up vote
1
down vote
favorite
I have 5 list box controls on a single windows form. I'm setting the enabled property to false initially to control read/edit access. This makes it hard to read the selected value without enabling the control. I'm using the enabled property as the ListBox control doesn't have a read-only property like TextBox controls.
I've seen approaches online where I can set
ListBox1.DrawMode = DrawMode.OwnerDrawFixed
And use Draw_Item to control the select item colour.
Private Sub ListBox1_DrawItem(ByVal sender As Object, _ ByVal e As System.Windows.Forms.DrawItemEventArgs) _
However, I've not seen an approach for applying this to multiple ListBox controls on a form. I don't really want to have to tap into Draw_Item for each ListBox.
Also, the ListBox controls are data bound to a DataSet. Anyone had this issue before? If so, how did you handle it?
Or does one know a way of controlling whether a ListBox control is read-only or selectable based on view/edit state?
Thanks in advance for any tips.
vb.net winforms listbox
It appears that you're not looking for a solution for the "problem", but a solution for the solution you came up with to solve the "problem". There's a two-letters-name for this situation. Maybe, you could explain why you need to disable those controls in the first place.
– Jimi
Nov 21 at 13:30
Hi, sure, the reason to disable them is so users cannot change them until they explicitly put the controls into edit mode. With TextBox controls I can use .ReadOnly, but the only thing I have on a ListBox is Enabled.
– Andrew Greatorex
Nov 21 at 13:35
ListBoxes are not editable, so this doesn't explain much. If, withedit mode, you mean you have some procedure that allows to insert/remove a ListBox's item(s), you should focus on that procedure. You can change the ForeColor of the Items in a disable ListBox(s), owner-drawing it, but is it really necessary? Doesn't it cause some confusion at some point? Can you manage it without causing collateral issues (e.g., Screen DPI changes, Font sizes, UI resizing)?
– Jimi
Nov 21 at 13:57
2
Well, you could (just a suggestion) have a Boolean field (e.g.,IsEditMode) that is set to false before editing is allowed. In theSelectedIndexChangedevent handler you could write something like:If Not IsEditMode Then ListBox1.SelectedIndex = -1 Return End If. This can give a visual clue that an Item can't be selected and any other code in the handler won't be executed.
– Jimi
Nov 21 at 14:19
1
I think i know what you are trying to pass across, when the listbox is disabled, the items on it cannot be seen properly, You can change the listbox's forecolor to a brighter color before disabling it.
– preciousbetine
Nov 22 at 1:39
|
show 4 more comments
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have 5 list box controls on a single windows form. I'm setting the enabled property to false initially to control read/edit access. This makes it hard to read the selected value without enabling the control. I'm using the enabled property as the ListBox control doesn't have a read-only property like TextBox controls.
I've seen approaches online where I can set
ListBox1.DrawMode = DrawMode.OwnerDrawFixed
And use Draw_Item to control the select item colour.
Private Sub ListBox1_DrawItem(ByVal sender As Object, _ ByVal e As System.Windows.Forms.DrawItemEventArgs) _
However, I've not seen an approach for applying this to multiple ListBox controls on a form. I don't really want to have to tap into Draw_Item for each ListBox.
Also, the ListBox controls are data bound to a DataSet. Anyone had this issue before? If so, how did you handle it?
Or does one know a way of controlling whether a ListBox control is read-only or selectable based on view/edit state?
Thanks in advance for any tips.
vb.net winforms listbox
I have 5 list box controls on a single windows form. I'm setting the enabled property to false initially to control read/edit access. This makes it hard to read the selected value without enabling the control. I'm using the enabled property as the ListBox control doesn't have a read-only property like TextBox controls.
I've seen approaches online where I can set
ListBox1.DrawMode = DrawMode.OwnerDrawFixed
And use Draw_Item to control the select item colour.
Private Sub ListBox1_DrawItem(ByVal sender As Object, _ ByVal e As System.Windows.Forms.DrawItemEventArgs) _
However, I've not seen an approach for applying this to multiple ListBox controls on a form. I don't really want to have to tap into Draw_Item for each ListBox.
Also, the ListBox controls are data bound to a DataSet. Anyone had this issue before? If so, how did you handle it?
Or does one know a way of controlling whether a ListBox control is read-only or selectable based on view/edit state?
Thanks in advance for any tips.
vb.net winforms listbox
vb.net winforms listbox
asked Nov 21 at 13:21
Andrew Greatorex
527
527
It appears that you're not looking for a solution for the "problem", but a solution for the solution you came up with to solve the "problem". There's a two-letters-name for this situation. Maybe, you could explain why you need to disable those controls in the first place.
– Jimi
Nov 21 at 13:30
Hi, sure, the reason to disable them is so users cannot change them until they explicitly put the controls into edit mode. With TextBox controls I can use .ReadOnly, but the only thing I have on a ListBox is Enabled.
– Andrew Greatorex
Nov 21 at 13:35
ListBoxes are not editable, so this doesn't explain much. If, withedit mode, you mean you have some procedure that allows to insert/remove a ListBox's item(s), you should focus on that procedure. You can change the ForeColor of the Items in a disable ListBox(s), owner-drawing it, but is it really necessary? Doesn't it cause some confusion at some point? Can you manage it without causing collateral issues (e.g., Screen DPI changes, Font sizes, UI resizing)?
– Jimi
Nov 21 at 13:57
2
Well, you could (just a suggestion) have a Boolean field (e.g.,IsEditMode) that is set to false before editing is allowed. In theSelectedIndexChangedevent handler you could write something like:If Not IsEditMode Then ListBox1.SelectedIndex = -1 Return End If. This can give a visual clue that an Item can't be selected and any other code in the handler won't be executed.
– Jimi
Nov 21 at 14:19
1
I think i know what you are trying to pass across, when the listbox is disabled, the items on it cannot be seen properly, You can change the listbox's forecolor to a brighter color before disabling it.
– preciousbetine
Nov 22 at 1:39
|
show 4 more comments
It appears that you're not looking for a solution for the "problem", but a solution for the solution you came up with to solve the "problem". There's a two-letters-name for this situation. Maybe, you could explain why you need to disable those controls in the first place.
– Jimi
Nov 21 at 13:30
Hi, sure, the reason to disable them is so users cannot change them until they explicitly put the controls into edit mode. With TextBox controls I can use .ReadOnly, but the only thing I have on a ListBox is Enabled.
– Andrew Greatorex
Nov 21 at 13:35
ListBoxes are not editable, so this doesn't explain much. If, withedit mode, you mean you have some procedure that allows to insert/remove a ListBox's item(s), you should focus on that procedure. You can change the ForeColor of the Items in a disable ListBox(s), owner-drawing it, but is it really necessary? Doesn't it cause some confusion at some point? Can you manage it without causing collateral issues (e.g., Screen DPI changes, Font sizes, UI resizing)?
– Jimi
Nov 21 at 13:57
2
Well, you could (just a suggestion) have a Boolean field (e.g.,IsEditMode) that is set to false before editing is allowed. In theSelectedIndexChangedevent handler you could write something like:If Not IsEditMode Then ListBox1.SelectedIndex = -1 Return End If. This can give a visual clue that an Item can't be selected and any other code in the handler won't be executed.
– Jimi
Nov 21 at 14:19
1
I think i know what you are trying to pass across, when the listbox is disabled, the items on it cannot be seen properly, You can change the listbox's forecolor to a brighter color before disabling it.
– preciousbetine
Nov 22 at 1:39
It appears that you're not looking for a solution for the "problem", but a solution for the solution you came up with to solve the "problem". There's a two-letters-name for this situation. Maybe, you could explain why you need to disable those controls in the first place.
– Jimi
Nov 21 at 13:30
It appears that you're not looking for a solution for the "problem", but a solution for the solution you came up with to solve the "problem". There's a two-letters-name for this situation. Maybe, you could explain why you need to disable those controls in the first place.
– Jimi
Nov 21 at 13:30
Hi, sure, the reason to disable them is so users cannot change them until they explicitly put the controls into edit mode. With TextBox controls I can use .ReadOnly, but the only thing I have on a ListBox is Enabled.
– Andrew Greatorex
Nov 21 at 13:35
Hi, sure, the reason to disable them is so users cannot change them until they explicitly put the controls into edit mode. With TextBox controls I can use .ReadOnly, but the only thing I have on a ListBox is Enabled.
– Andrew Greatorex
Nov 21 at 13:35
ListBoxes are not editable, so this doesn't explain much. If, with
edit mode, you mean you have some procedure that allows to insert/remove a ListBox's item(s), you should focus on that procedure. You can change the ForeColor of the Items in a disable ListBox(s), owner-drawing it, but is it really necessary? Doesn't it cause some confusion at some point? Can you manage it without causing collateral issues (e.g., Screen DPI changes, Font sizes, UI resizing)?– Jimi
Nov 21 at 13:57
ListBoxes are not editable, so this doesn't explain much. If, with
edit mode, you mean you have some procedure that allows to insert/remove a ListBox's item(s), you should focus on that procedure. You can change the ForeColor of the Items in a disable ListBox(s), owner-drawing it, but is it really necessary? Doesn't it cause some confusion at some point? Can you manage it without causing collateral issues (e.g., Screen DPI changes, Font sizes, UI resizing)?– Jimi
Nov 21 at 13:57
2
2
Well, you could (just a suggestion) have a Boolean field (e.g.,
IsEditMode) that is set to false before editing is allowed. In the SelectedIndexChanged event handler you could write something like: If Not IsEditMode Then ListBox1.SelectedIndex = -1 Return End If. This can give a visual clue that an Item can't be selected and any other code in the handler won't be executed.– Jimi
Nov 21 at 14:19
Well, you could (just a suggestion) have a Boolean field (e.g.,
IsEditMode) that is set to false before editing is allowed. In the SelectedIndexChanged event handler you could write something like: If Not IsEditMode Then ListBox1.SelectedIndex = -1 Return End If. This can give a visual clue that an Item can't be selected and any other code in the handler won't be executed.– Jimi
Nov 21 at 14:19
1
1
I think i know what you are trying to pass across, when the listbox is disabled, the items on it cannot be seen properly, You can change the listbox's forecolor to a brighter color before disabling it.
– preciousbetine
Nov 22 at 1:39
I think i know what you are trying to pass across, when the listbox is disabled, the items on it cannot be seen properly, You can change the listbox's forecolor to a brighter color before disabling it.
– preciousbetine
Nov 22 at 1:39
|
show 4 more comments
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53412994%2flistbox-control-winforms-selected-item-color-multiple-list-box-controls%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
It appears that you're not looking for a solution for the "problem", but a solution for the solution you came up with to solve the "problem". There's a two-letters-name for this situation. Maybe, you could explain why you need to disable those controls in the first place.
– Jimi
Nov 21 at 13:30
Hi, sure, the reason to disable them is so users cannot change them until they explicitly put the controls into edit mode. With TextBox controls I can use .ReadOnly, but the only thing I have on a ListBox is Enabled.
– Andrew Greatorex
Nov 21 at 13:35
ListBoxes are not editable, so this doesn't explain much. If, with
edit mode, you mean you have some procedure that allows to insert/remove a ListBox's item(s), you should focus on that procedure. You can change the ForeColor of the Items in a disable ListBox(s), owner-drawing it, but is it really necessary? Doesn't it cause some confusion at some point? Can you manage it without causing collateral issues (e.g., Screen DPI changes, Font sizes, UI resizing)?– Jimi
Nov 21 at 13:57
2
Well, you could (just a suggestion) have a Boolean field (e.g.,
IsEditMode) that is set to false before editing is allowed. In theSelectedIndexChangedevent handler you could write something like:If Not IsEditMode Then ListBox1.SelectedIndex = -1 Return End If. This can give a visual clue that an Item can't be selected and any other code in the handler won't be executed.– Jimi
Nov 21 at 14:19
1
I think i know what you are trying to pass across, when the listbox is disabled, the items on it cannot be seen properly, You can change the listbox's forecolor to a brighter color before disabling it.
– preciousbetine
Nov 22 at 1:39