By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,234 Members | 1,850 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,234 IT Pros & Developers. It's quick & easy.

Dataset - DataGrid - ComboBox

P: n/a
What's wrong here?

Sub ShowDG()
DsIllness1.Clear()
DsIllness1.tblIllness.illIDColumn.ColumnMapping = MappingType.Hidden
DsIllness1.tblIllness.illDescColumn.ColumnMapping = MappingType.Hidden

Try
OleDbDataAdapter1.Fill(DsIllness1)
dg.DataSource = DsIllness1.DefaultViewManager
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Sub Check()
If comboLang.SelectedIndex = 0 Then
DsIllness1.tblIllness.illNameEColumn.ColumnMapping = MappingType.Hidden '
**********LINE 1
dg.RightToLeft = RightToLeft.Yes ' *********LINE 2
Else
DsIllness1.tblIllness.illNameFColumn.ColumnMapping = MappingType.Hidden '
**********LINE 3
dg.RightToLeft = RightToLeft.No ' **********LINE 4
End If
ShowDG()
End Sub

Private Sub comboLang_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles comboLang.SelectedIndexChanged
Check()
End Sub
When I select an item of combo box, it goes to Check() sub, but just LINE2
and LINE4 works and

LINE 3 or LINE 4 does not work.
--
Saber S.
http://maghalat.com
Nov 21 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Saber,

I think that there is more wrong, however to start, a combobox selectedindex
change event starts already to fire if you set the datasource of a combobox.

Therefore are a lot of solutions. One of the easiest ones is to set a switch
that you set to false or true if the combobox is complete initialized.

(The defaultview is often a datasource, I never saw the defaultviewmanager
for that)

I hope this helps,

Cor
Nov 21 '05 #2

P: n/a
> Saber,

I think that there is more wrong, however to start, a combobox
selectedindex change event starts already to fire if you set the
datasource of a combobox. Thanks Cor,
You mean if I select an item of combobox in runtime, its SelectedIndex
property
doesn't changes?

Therefore are a lot of solutions. One of the easiest ones is to set a
switch that you set to false or true if the combobox is complete
initialized. Would you please tell me more about it: "if the combobox is complete
initialized."
I'm not sure if I get whay you say. What if I have 3 items in combobox?
(The defaultview is often a datasource, I never saw the defaultviewmanager
for that) Well, you see it now. ;) (kidding)
I saw your sample here:
http://www.windowsformsdatagridhelp....3-a3539697edbd

You create a datatable, and then: DataGrid1.DataSource = dt.DefaultView

What if doing it without datatable?
defaultviewmanager works fine, is it really a mistake to use it here?

I hope this helps,
It really helps.
Cor

Nov 21 '05 #3

P: n/a
Saber,

Very roughly

Globaly
Private loaded as boolean

In the load event
combobox1.datasource = mytable
etc
loaded = true

In your selected index change event
if loaded then....................
do what you want to do with the combobox.

end if

I hope this helps,

Cor
Nov 21 '05 #4

P: n/a
Sorry Cor,
I think I couldn't tell you what I want to do.
There is a combobox with 2 items: Persian, English
The items in this combobox are just this 2 values.
When user, selects English, actually he selects index 1
and Persian's index is 0.
I've two columns in a table of my database, illNameF which
is Persian illness names and illNameE is English illness names.
I want when user selects Persian in combobox, hide illNameE
in datagird and when selects English, hide illNameF.
also there are two other columns in that table, they will hide easily.
(by the code I posted already)
in Page Load event, when I set combobox.selectedindex to 0 or 1, it
hides illNameE or illNameF but in runtime when I change combobox item,
it doesn't hides other column.

--
Saber S.
http://maghalat.com
"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Saber,

Very roughly

Globaly
Private loaded as boolean

In the load event
combobox1.datasource = mytable
etc
loaded = true

In your selected index change event
if loaded then....................
do what you want to do with the combobox.

end if

I hope this helps,

Cor

Nov 21 '05 #5

P: n/a
Saber,

If I understand you well, than would I first of all not use a combobox for
that, much to difficult for you and the user while the checkbox and the
radiobutton are made for what you tell.

Your problem is easily to solve with setting the mapping to hidden. That has
to be in advance of setting the datasource.

I made this morning a sample for that for somebody else. Have a look at
that.

http://www.windowsformsdatagridhelp....6-0ea05b3e1bee

I hope this helps,

Cor

Nov 21 '05 #6

P: n/a
Cor,
I think the error is somewhere else.
I deleted the combobox and simply put 2 buttons on the form.
Sub ShowDG()
DsIllness1.Clear()
DsIllness1.tblIllness.illIDColumn.ColumnMapping = MappingType.Hidden
DsIllness1.tblIllness.illDescColumn.ColumnMapping = MappingType.Hidden
Try
OleDbDataAdapter1.Fill(DsIllness1)
dg.DataSource = DsIllness1.DefaultViewManager
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Private Sub btnFullList_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnFullList.Click

OleDbDataAdapter1.SelectCommand.CommandText = "SELECT illDesc, illID,
illNameE, illNameF FROM tblIllness"
DsIllness1.tblIllness.illNameFColumn.ColumnMapping = MappingType.Hidden
dg.RightToLeft = RightToLeft.No
ShowDG()

End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

OleDbDataAdapter1.SelectCommand.CommandText = "SELECT illDesc, illID,
illNameE, illNameF FROM tblIllness"
DsIllness1.tblIllness.illNameEColumn.ColumnMapping = MappingType.Hidden
dg.RightToLeft = RightToLeft.Yes
ShowDG()

End Sub
When I click btnFullList, it is OK and it does what I desire.
also When I click Button1, it is OK and it does what I desire.

But the problem is here, I click btnFullList and then Button1 or vise versa.
It just changes RightToLeft, and previous ColumnMapping doesn't changes.
I need a way (a sub routine) to reset ColumnMapping=MappingType.Hidden

Thanks

--
Saber S.
http://maghalat.com
"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
Saber,

If I understand you well, than would I first of all not use a combobox for
that, much to difficult for you and the user while the checkbox and the
radiobutton are made for what you tell.

Your problem is easily to solve with setting the mapping to hidden. That
has to be in advance of setting the datasource.

I made this morning a sample for that for somebody else. Have a look at
that.

http://www.windowsformsdatagridhelp....6-0ea05b3e1bee

I hope this helps,

Cor

Nov 21 '05 #7

P: n/a
Saber,

Why don't you than not set the mapping type to another one?

http://msdn.microsoft.com/library/de...classtopic.asp

I did not test which however that you can do yourself in my opinon.

I hope this helps,

Cor
Nov 21 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.