Dataset - DataGrid - ComboBox

  • Thread starter Thread starter Saber
  • Start date Start date
S

Saber

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,

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
 
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.com/default.aspx?ID=76a81eb8-ea2d-48f4-99c3-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.
 
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
 
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,

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.com/default.aspx?ID=334417f1-bf12-4836-88d6-0ea05b3e1bee

I hope this helps,

Cor
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top